我正在使用硒测试自动化。 我想使用Xpath识别元素
它的HTML结构如下:
<p class="ng-binding"> <span class="ng-binding">Patrik</span> Thomson </p>我想构建Xpath,它可以使用名字和姓氏来识别整个元素。
可能有2个Xpath模式,下面是示例模式1: /x:html/x:body/x:div[1]/x:div/x:div/x:div
模式2: /ul/li[@class='ng-scope'][@title='For']
我想使用模式2来识别我的元素,我使用FirstName和Last Name进行搜索。
I am in to test automation using selenium. I want to identify element using Xpath
Its HTML structure is like this:
<p class="ng-binding"> <span class="ng-binding">Patrik</span> Thomson </p>I want to build Xpath, which can identify this entire element using First Name & Last Name.
There could be 2 Pattern of Xpath, below are examples Pattern 1: /x:html/x:body/x:div[1]/x:div/x:div/x:div
Pattern 2: /ul/li[@class='ng-scope'][@title='For']
I want to identify my element using pattern 2 where I search using FirstName & Last Name.
最满意答案
你可以在xpath下面使用
"//p[contains(.,'Thomson')]/span[text()='Patrik']"使用firstName和lastName定位元素后,您可以根据需要使用xpath中可用的函数向后,向后遍历。
You could use below xpath
"//p[contains(.,'Thomson')]/span[text()='Patrik']"After locating the element using firstName & lastName , you can traverse forward, backward using function available in xpath based on your requirement.
更多推荐
发布评论