Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
如何在SeleniumWebDriver中为下面的HTML表达式编写xpath?_Selenium - Fatal编程技术网

如何在SeleniumWebDriver中为下面的HTML表达式编写xpath?

如何在SeleniumWebDriver中为下面的HTML表达式编写xpath?,selenium,Selenium,我为下面显示的HTML代码编写了xpath 1. //a[@text()='Life Insurance'] 2. //span[@text()='Apply now'] 但我得到的元素没有找到异常。若我使用了绝对xpath处理器,那个么它工作正常,我编写了自己的xpath,然后它抛出了异常。 请告诉我怎么写 下面是我需要的HTML代码xpath 1.<a class="mainlink" href="https://leads.hdfcbank.com/applications/

我为下面显示的HTML代码编写了
xpath

1.   //a[@text()='Life Insurance']
2.  //span[@text()='Apply now']
但我得到的元素没有找到异常。若我使用了绝对xpath处理器,那个么它工作正常,我编写了自己的xpath,然后它抛出了异常。 请告诉我怎么写

下面是我需要的HTML代码
xpath

1.<a class="mainlink" href="https://leads.hdfcbank.com/applications/webforms/apply/HDFC_Life_Click2Protect/index.aspx?promocode=P4_hp_AppNow_LI" target="" rel="nofollow width=375 height=213">Life Insurance</a> 

2." <div class="menutext"> <span class="mainlink">Apply now</span> <img class="pointer" alt="Pointer" src="/assets/images/nav_pointer.png" style="display: none;"> </div> "
1。
2.“立即申请”
试试这些 一

//a[text()=“人寿保险”]

两个

//span[text()=“立即应用”]

试试这些 一

//a[text()=“人寿保险”]

两个

//span[text()=“立即应用”]


您必须删除代码中的“@”。 (或)

您还可以使用:

 //a[contains(text(),'Life Insurance')]
两个

  //span[contains(text(),'Apply now')]

您必须删除代码中的“@”。 (或)

您还可以使用:

 //a[contains(text(),'Life Insurance')]
两个

  //span[contains(text(),'Apply now')]

我在一些在线xpath验证器中尝试过它:(.我也在这方面尝试过…也许你正在使用更复杂的html…所以最好直接在这些网站上尝试一下。它工作得很好。但是我得到了“元素当前不可见,因此可能无法与命令持续时间或超时进行交互:181毫秒”有时会出错。请告诉我,按照惯例,我们应该编写类似xpath的(//HTMLtagname[@attribute name='value']),但上面的代码在没有“@”的情况下工作。如何?@在xpath中表示属性请参阅此处了解更多详细信息@表示属性,但此代码“//a[text()='Life Insurance']”在没有针对属性的@representation的情况下工作。请告诉我[text()='Life Insurance']是如何工作的。我在一些在线xpath验证器中尝试过它,它正在工作:(.我也在这方面尝试过…也许你在更复杂的html中使用它..所以最好直接在这些网站上尝试一下。它工作得很好。但是我得到了“元素当前不可见,因此有时可能无法与命令持续时间或超时进行交互:181毫秒”错误。请您告诉我,按照惯例,我们应该编写类似xpath的(//HTMLtagname[@attribute name='value']),但上面的代码没有”@“.How?@在XPath中表示属性有关详细信息,请参见此处。我知道@representation属性,但此代码“//a[text()='Life Insurance']”在没有针对属性的@representation的情况下工作。请告诉我//a[text()='Life Insurance']是如何工作的。