Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99042

How to read text from hidden element with Selenium WebDriver?

$
0
0

I'm trying to read the example String 1000 out of a hidden <div> like this:

<div id="hidden_div" style="visibility:hidden">1000</div>

I am aware that WebElement.getText() does not work on hidden elements in Selenium 2 (WebDriver), so I searched for solutions (like this one) and apparently the following code should work:

WebElement hiddenDiv = seleniumDriver.findElement(By.id("hidden_div"));String n = hiddenDiv.getText(); // does not work (returns "" as expected)String script = "return arguments[0].innerText";n = (String) ((JavascriptExecutor) driver).executeScript(script, hiddenDiv);

But it doesn't work for me, the variable n always ends up as null. What am I doing wrong?


Viewing all articles
Browse latest Browse all 99042

Latest Images

Trending Articles



Latest Images