2024-10-03 00:28:27 发布
网友
我需要找到以下元素的XPath:
<a> href="/resident/register/">Register another device </a>
我以为解决办法是
$x("//*[contains(@href, 'resident/register')]")
但这并没有带来任何回报。有什么想法吗?你知道吗
从@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']"
你的HTML格式不正确。你知道吗
改变
至
然后XPath将按预期工作。你知道吗
如果HTML是固定的,则必须调整XPath以测试元素内容,而不是href属性内容:
href
//a[contains(.,'resident/register')]
但是,尽管这可以选择格式错误的a元素,但由于它缺少适当的href属性,因此无法单击。你知道吗
a
从@kjhughes开始,解决了HTML的一个问题,即HTML的格式不正确,因为您必须根据自己的理解提供正确的HTML。你知道吗
实际的HTML我想如下:
因此,元素的有效XPath可以是以下任一项:
XPath:1
XPath:2
你的HTML格式不正确。你知道吗
改变
至
然后XPath将按预期工作。你知道吗
如果HTML是固定的,则必须调整XPath以测试元素内容,而不是
href
属性内容:但是,尽管这可以选择格式错误的
a
元素,但由于它缺少适当的href
属性,因此无法单击。你知道吗相关问题 更多 >
编程相关推荐