1

Am using a piece of code below to get the text of some particular locator.

WebElement ele=driver.findElement(By.cssSelector("Some locator"));
ele.getText();

This returns the string value,but only in IE browser it failed and worked in rest of the browsers i.e., Firefox and chrome.

Am facing this issue:

org.openqa.selenium.WebDriverException: Unable to get element text (WARNING: The server did not provide any stacktrace information)

Please help me out in this and this exception in IE browser is also very inconsistent some times it passes and some times failed same code.

2
  • This might help you: stackoverflow.com/a/23795692/742269 Commented Mar 22, 2016 at 7:52
  • i think both are different,am able to find the element but unable to get the text of it Commented Mar 22, 2016 at 7:54

2 Answers 2

1

Jsoup is a great html parser, use Jsoup while you are using selenium they can get along each other.

String web_page = driver.getPageSource();//selenium driver is getting the whole page
Document xml_doc = Jsoup.parse(web_page); //jsoup parsing web page
String str= xml_doc.getElementById("Some locator").text();//get text and assign it to str

http://jsoup.org/

Sign up to request clarification or add additional context in comments.

Comments

0

I've a couple issues when getting text from elements so I get attribute "innerText" instead. Try code below:

if(element.getAttribute("innerText") != null)
    element.getAttribute("innerText").Trim();
else 
    element.getText().Trim();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.