Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以下元素的XPath是什么?_Python_Html_Xml_Selenium_Xpath - Fatal编程技术网

Python 以下元素的XPath是什么?

Python 以下元素的XPath是什么?,python,html,xml,selenium,xpath,Python,Html,Xml,Selenium,Xpath,我需要找到以下元素的XPath: <a> href="/resident/register/">Register another device </a> 但这并没有带来任何回报。有什么想法吗?您的HTML格式不正确 改变 <a> href="/resident/register/">Register another device </a> 但是,尽管这可以选择格式不正确的a元素,但它将无法单击,因为它缺少适当的href属性。从@kj

我需要找到以下元素的XPath:

<a> href="/resident/register/">Register another device </a>

但这并没有带来任何回报。有什么想法吗?

您的HTML格式不正确

改变

<a> href="/resident/register/">Register another device </a>

但是,尽管这可以选择格式不正确的
a
元素,但它将无法单击,因为它缺少适当的
href
属性。

从@kjhughes开始,解决了HTML的一个问题,即HTML格式不正确,因为您必须根据自己的理解尝试提供正确的HTML

我认为实际的HTML如下所示:

<a href="/resident/register/">Register another device </a>
  • XPath:2


  • “有什么想法吗?”您可能需要检查:。这取决于页面其余部分的构建方式。无论哪种方式,Hi@Sam1811x,请尝试以下方法:
    //a[text()='Register other device']
    locator注意,元素没有“the”XPath这样的东西。您通常希望选择一个XPath表达式,该表达式唯一地标识文档中的元素,并且在文档发生微小更改时保持稳定。因此,XPath的最佳选择非常依赖于上下文。但您失败的原因似乎是
    href
    实际上不是一个属性,它似乎输入错误。
    <a href="/resident/register/">Register another device </a>
    
    //a[contains(.,'resident/register')]
    
    <a href="/resident/register/">Register another device </a>
    
    "//a[contains(@href, '/resident/register') and contains(.,'Register another device')]"
    
    "//a[contains(@href, '/resident/register') and normalize-space()='Register another device']"