Cannot get text of the element but can click on the element | Selenium Webdriver Tutorial with c# |Selenium C# training
15% Colorful Festival Offer Avail now

Selenium C# Training Forum

cannot get text of the element but can click on the element

Vrushali Haldankar Post on 10/01/2019

Please help me to resole the issue

1. I can click on the element but not getting the text of the element

2. I tried 7-10 approaches to get text of element but no result.

# getattribute("text")

#  Using below code

String script = "return jQuery(arguments[0]).text();";
 js = driver as IJavaScriptExecutor;
 string n=(string)js.ExecuteScript(script, acto_wo);

 #chaging xpath of element

//div[@class='col-md-12 h65 boxed-outline-total hoverable']//div//span[@class='boldText ng-binding'][contains(text(),'229')]
//*[@id="Dashboard"]/div[1]/div/div[2]/div[1]/div/div[2]/span section.maincontent-section:nth-child(4) div.container div.container div.row div.row div.tabContent div.row:nth-child(1) div.col-sm-2:nth-child(1) div.showhim.topDataContainer.h80.boxed-outline.centerText.pointMe.svgPipeline.dashboardSelect div.row.showme div.col-md-8 div.col-md-12.h65.boxed-outline-total.hoverable div:nth-child(2) >
#Dashboard > div:nth-child(1) > div > div.row.showme > div.col-md-8 > div > div:nth-child(2) > span
IWebElement acto_wo=driver.FindElement(By.CssSelector("#Dashboard > div:nth-child(3) > div > div.row.showme > div.col-md-8 > div > div:nth-child(2) > span"));

            js = driver as IJavaScriptExecutor;
            js.ExecuteScript("arguments[0].click();", acto_wo);

            Console.WriteLine(acto_wo.Text); // not getting the Text




gunjan Reply on 11/01/2019

Use the Text property to get the text of the element, not the getAttribute("text") property.

For example.,

driver.FindElement(By.Xpath(xpath of element)).Text;

Vrushali Haldankar Reply on 11/01/2019

I used it .then also not working

Demo Reply on 13/01/2019

Put a little delay before reading text.. let the page source load

and... make sure its not a frame