I\'m trying to read the example String I came across the same problem of reading invisible elements but I wanted back a WebElement object to do further parsing (not just its text). This bit of code fulfilled my requirement. Might be useful as well: In some cases, one may find it useful to get the hidden text, which can be retrieved from element's See more details there ->
http://yizeng.me/2014/04/08/get-text-from-hidden-elements-using-selenium-webdriver/ I'm relatively new to Selenium (and to programming as whole), but I'm just sharing a solution that worked for me. Selenium 2 was not designed for handling elements with hidden visibility directly. You won't be able to find it's ID or CSS Selector, for example. I had a situation with a bot where I had a HTML table with lots of itens, and when clicking when of them, a dropdown with hidden visibility openned. It was even in another frame. It's a specific situation, but I couldn't find any solution, so I chose this (bad) one, but that works really consistently, despite the ugly code. First you should Than: The dataCells are literally the It worked on Chrome and Firefox for me, but not on any headless browser, not sure exactly why. If you guys come across anything like that and have a more elegant solution (probably not so difficult to find it), please share! Try this Building upon the work of the already given answers, I created this utility method (Java). Maybe this is helpful for someone else. When we come across any such case, first thing we should do is to try any action which doesn't make any change on that page, like drag etc, then do a frame switch. Try a 1000
out of a hidden
(WebElement) ((JavascriptExecutor) driver).executeScript(
"arguments[0].style[\"display\"] = \"block\";"+
"arguments[0].style[\"visibility\"] = \"visible\";"+
"return arguments[0];",
element);
textContent
, innerText
or innerHTML
attribute, by calling element.attribute('attributeName')
.element.getAttribute("textContent")
worked for me.switchToDesiredFrame();
- enter your driver.switchTo.frame()
logic here. WebElement table = driver.findElements(By.tagName("table")).get(index_1);
List<WebElement> dataCells= table .findElements(By.tagName("td"));
WebElement spceificDataCellIWanted = dataCells.get(index_2);
System.out.println(spceificDataCellIWanted.getText());
<td>
tags, and they become WebElements
in a list just as <td>
's are the elements in a list under the <table>
"container". WebElement hiddenElement = GET YOUR ELEMENT HERE;
String hiddenContent= hiddenElement.getAttribute("textContent");
public static String getText(WebDriver driver, WebElement element){
return (String) ((JavascriptExecutor) driver).executeScript(
"return jQuery(arguments[0]).text();", element);
}
type='hidden'
getText()
, if that doesn't work, try the above as the 2nd alternative.