Cannot get text of the element but can click on the element | Selenium C# Forum
V
Vrushali Posted 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);
 Console.WriteLine(n);

 #chaging xpath of element

/html/body/section/div/div/div/div/div/ng-view/div/div/div/div/div[1]/div[1]/div/div[2]/div[1]/div/div[2]/span
//div[@class='col-md-12 h65 boxed-outline-total hoverable']//div//span[@class='boldText ng-binding'][contains(text(),'229')]
/html[1]/body[1]/section[1]/div[1]/div[1]/div[1]/div[1]/div[1]/ng-view[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[2]/span[1]
//*[@id="Dashboard"]/div[1]/div/div[2]/div[1]/div/div[2]/span
body.ng-scope:nth-child(2) section.maincontent-section:nth-child(4) div.container div.container div.row ng-view.ng-scope div.container.ng-scope div.row div.tab 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) > span.boldText.ng-binding
#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);

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

 

G
gunjan Replied 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;


V
Vrushali Replied on 11/01/2019

I used it .then also not working


A
Ashish Thakur Replied on 13/01/2019

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

and... make sure its not a frame


S
Support Desk Replied on 25/05/2019

Is the issue resolved?


V
Vrushali Replied on 11/06/2019

yess