[英]How to click on a link inside span inside <a class> with using xpath
Using xpath, sélénium doesn't recognize the element, what's the correct xpath? 使用xpath,sélénium无法识别元素,正确的xpath是什么?
HTML: HTML:
<a class="xmi" onclick="this.focus();return false; "href="#">
<span title="">SITE A</span>
</a>
My XML locator file: 我的XML定位器文件:
<domElements>
<name>Site_A</name>
<locators>
<type>XPATH</type>
<value>//span[contains(@title,'SITE A')]</value>
<priority>0</priority>
</locators>
</domElements>
Java code calling my locator: 调用我的定位器的Java代码:
this.locate("Site_A").click();
}
} }
SITE A
is not the title (which is an empty string in this case), it's the element text. SITE A
不是标题(在这种情况下是一个空字符串),它是元素文本。 Use text()
or .
使用text()
或.
to locate it 找到它
//span[contains(., 'SITE A')]
If the element is inside <iframe>
you need to swith to it first 如果元素在<iframe>
内部,则需要先切换到它
driver.switchTo().frame("afr::PushIframe");
SITE A
is not the value attribute but the innerHTML , so you need to: SITE A
不是值属性而是innerHTML ,因此您需要:
<domElements>
<name>Site_A</name>
<locators>
<type>XPATH</type>
<value>//span[@title and text()='SITE A']</value>
<priority>0</priority>
</locators>
</domElements>
As an alternative you can also change the <value>
to include the parent node as: 作为替代方案,您还可以更改<value>
以将父节点包括为:
<domElements>
<name>Site_A</name>
<locators>
<type>XPATH</type>
<value>//a[@class='xmi']/span[@title and text()='SITE A']</value>
<priority>0</priority>
</locators>
</domElements>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.