I would like to use getText()
for one XPath, need text what is there.
//span(contains(@style,'display:none'))
XPath is working tested in firebug, I've tried getText
, getAttribute
, so far no luck
I would like to use getText()
for one XPath, need text what is there.
//span(contains(@style,'display:none'))
XPath is working tested in firebug, I've tried getText
, getAttribute
, so far no luck
It's a little hard to say without the exact HTML, which you have not specified in your question...
To begin with, you need to change this:
"//span(contains(@style,'display:none'))"
To this:
"//span[contains(@style,'display:none')]"
UPDATE:
Alternatively, since the span
element is not visible, you might be able to do it with:
String innerHTML = elem.getAttribute("innerHTML");
Where elem
is the parent node of the span
element.
Then, in order to get the actual text, you will need to parse the innerHTML
string.
Because the element is invisible (it has display:none
), Selenium cannot natively interact with it. You need cast your driver to JavascriptExecutor
, then execute the following javascript:
$x("//span(contains(@style,'display:none'))")[0].text
The [0]
returns the 1st element returned by the xpath.
This will return the inner text of the element.