需要xpath我的特定dom元素来识别该元素(selenium web driver)(Need xpath for my specific dom element to identify that

编程入门 行业动态 更新时间:2024-10-24 13:24:52
需要xpath我的特定dom元素来识别该元素(selenium web driver)(Need xpath for my specific dom element to identify that element (selenium web driver))

我正在使用硒测试自动化。 我想使用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.

更多推荐

本文发布于:2023-07-31 01:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   selenium   xpath   dom   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!