<span id="UniversalRepositoryExplorer_treeNode7_name" style="white-space:nowrap;"> == $0
<img id="UniversalRepositoryExplorer_treeNodeIcon_7" src="../../images/server_running.gif"
style="width:16px;height:16px;" alt border="0"> == $0
" Running " == $0
tag span has inside tag img and below text Running doesn't have any tag name
I have tried the below x-path that didn't work:
//img[@id='UniversalRepositoryExplorer_treeNodeIcon_7']
Can someone suggest to me how to get Running through x-path?
CodePudding user response:
Looking at the element you have noted above, if I was trying to evaluate for a cucumber step, I would write this for selenium-java:
@And("^I can view the \"([^\"]*)\" image$")
public void iCanViewTheImage(String text) throws Throwable {
String imgXpath = "//span[contains(text(),'" text "') and contains(@id, 'UniversalRepositoryExplorer_treeNode7_name')]//img[@id='UniversalRepositoryExplorer_treeNodeIcon_7'];
driver.findElement(By.xpath(imgXpath));
assertTrue(driver.findElement(By.xpath(imgXpath)).getText().contains(text));
}
where the regex "([^"]*)" would be "Running" in your cucumber step: And I can view the "Running" image
CodePudding user response:
Basically, you're trying to get the text node.
xpath: '//span/text()[last()]'
Example:
document.evaluate("//span/text()[last()]", window.document, null, XPathResult.ANY_TYPE, null).iterateNext()
// output: " Running "