![](/img/trans.png)
[英]what exactly happening when i am calling the following function called find_element_by_xpath?
[英]What is the XPath for the following element?
我需要找到以下元素的 XPath:
<a> href="/resident/register/">Register another device </a>
我认为解决方案是
$x("//*[contains(@href, 'resident/register')]")
但这没有任何回报。 有任何想法吗?
您的 HTML 格式不正确。
改变
<a> href="/resident/register/">Register another device </a>
到
<a href="/resident/register/">Register another device </a>
那么您的 XPath 将按预期工作。
如果您的 HTML 是固定的,那么您必须调整 XPath 以测试元素内容而不是href
属性内容:
//a[contains(.,'resident/register')]
但是,尽管这可以选择格式错误a
元素,但由于缺少适当的href
属性,因此无法单击。
首先,@kjhughes 解决了HTML 的一个问题,即HTML 格式错误,因为您必须尝试根据自己的理解提供正确的 HTML。
我想的实际HTML如下:
<a href="/resident/register/">Register another device </a>
因此元素的有效XPath可以是以下之一:
XPath:1
"//a[contains(@href, '/resident/register') and contains(.,'Register another device')]"
XPath:2
"//a[contains(@href, '/resident/register') and normalize-space()='Register another device']"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.