Facing issue to read content after clicking an element in Selenium. I have tried with below code:

if(webElement2.isDisplayed()) {

String tagContent = (String) ((JavascriptExecutor) 
BrowserUtilities.getDriver()).executeScript("return arguments[0].innerText;", webElement2);
  • 2
    Please update your question with the error you're seeing.
    – anonygoose
    Feb 5 '19 at 13:06

Your code does the following:

  • If webElement2 is displayed, wait for some other element, webElement, to be visible and click on webElement2;
  • Grab the text on webElement2.

It can be failing because webElement2 is never displayed.

Probably, what you want is:

  • If webElement2 is not displayed, click on webElement (not webElement2);
  • Wait for webElement2 to be visible;
  • Grab the text from webElement2.

OBS: I will edit this answer based on @anonygoose's request.


Try to get the attributes of the webElement2 which you are referring at your code.

String aa = webElement2.getAttribute("text").toString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.