[英]How to identify element using following-sibling method in selenium
Following code I need to identify third li element(user list).下面的代码我需要识别第三个li元素(用户列表)。 How I co do using selenium?我如何合作使用硒?
I have tried using,我试过使用,
String usertype= //td[text()='product']
String usersubtype= li[@class='user-list dropbutton-action secondary-action']
String adduser = usertype +"following-sibling::td//" +usersubtype+"/a"
I must use following method.我必须使用以下方法。 Because my code usertype and usersubtype values coming from different place因为我的代码usertype和usersubtype值来自不同的地方
(above strings just for reference) (以上字符串仅供参考)
But it could not work out.但它无法解决。 Please help me to identify the third li element(user list)请帮我识别第三个li元素(用户列表)
I need to identify following element in the code我需要识别代码中的以下元素
<li class="content-list dropbutton-action secondary-action"><a href="/admin/structure/eck/entity/product">User list</a></li>
Below is my code snippet:下面是我的代码片段:
<tr class="even">
<td>product</td>
<td>product</td>
<td>
<div class="code-wrapper dropbutton-multiple">
<div class="dropbutton-widget">
<ul class="dropbutton">
<li class="user dropbutton-action"><a href="/user/userlist/abc/productcontent/add">Add User</a></li>
<li class="dropbutton-toggle"><button type="button"><span class="dropbutton-arrow"><span class="visually-hidden">List actions</span></span></button></li>
<li class="user-list dropbutton-action secondary-action"><a href="/user/userlist/abc/productproduct">User list</a></li>
<li class="user-list dropbutton-action secondary-action"><a href="/user/userlist/abc/productproduct/types">Test list</a></li>
<li class="edit dropbutton-action"><a href="/user/userlist/abc/productmanage/product?destination=/admin/structure/eck/entity_type">Edit</a></li>
<li class="delete dropbutton-action"><a href="/user/userlist/abc/productmanage/product/delete?destination=/admin/structure/eck/entity_type">Delete</a></li>
</ul>
</div>
</div>
</td>
The issue with your locator is that it is incorrect.您的定位器的问题在于它不正确。 The double slash is missing from the following-sibling::
. following-sibling::
缺少双斜线following-sibling::
。
Try changing:尝试改变:
//td[text()='product']following-sibling::td//li[@class='user-list dropbutton-action secondary-action']
To至
//td[text()='product']//following-sibling::td//li[@class='user-list dropbutton-action secondary-action']/a
Complete code:完整代码:
String usertype= //td[text()='product']
String usersubtype= li[@class='user-list dropbutton-action secondary-action']
String adduser = usertype +"//following-sibling::td//" +usersubtype+"/a"
Why not simply:为什么不简单:
//li[contains(@class,'content-list')]
or with css selector或使用 css 选择器
li.content-list
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.