简体   繁体   English

如何使用硒中的兄弟姐妹方法识别元素

[英]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因为我的代码usertypeusersubtype值来自不同的地方

(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"

Screenshot:截屏: 在此处输入图片说明

Why not simply:为什么不简单:

//li[contains(@class,'content-list')]

or with css selector或使用 css 选择器

li.content-list

? ?

如何使用following-sibling全部点击<li>里面<ul java< div><div id="text_translate"><p> 我可以点击“Mentorship”li 标签,但我想点击每个 li,从“Mentorship”标签链接开始</p><pre>&lt;ul _ngcontent-cwp-c18="" class="navigation clearfix"&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current" class=""&gt;&lt;a _ngcontent-cwp-c18="" href="#/index"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18=""&gt;&lt;a _ngcontent-cwp-c18="" href="https://courses.rahulshettyacademy.com/courses"&gt;Courses&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current" class="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/mentorship"&gt;Mentorship&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/practice-project"&gt;Practice Projects&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/consulting"&gt;Consulting&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/part-time-jobs"&gt;Earn&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18=""&gt;&lt;a _ngcontent-cwp-c18="" href="http://www.qaclickacademy.com/blog/"&gt;Articles&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/about-my-mission"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/contact-us"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;</pre><p> 这是我试过的:</p><pre> driver.get("http://www.qaclickacademy.com/"); driver.findElement(By.xpath("//ul[@class='nav navbar-nav navbar-right']//a[contains(text(),'Interview Guide')]")).click(); //mentorship driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]").click(); //practice projects driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]/following-sibling::li[1]").click(); //consulting driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]/following-sibling::li[2]").click(); //earn driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]/following-sibling::li[3]").click();</pre><p> 请问,我如何使用以下兄弟姐妹点击每一行,从特定的一行开始?</p></div></ul></li> - How to use following-sibling to click in all <li> inside <ul JAVA

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取表类型结构的以下兄弟元素 - How to get the following-sibling element for a table type of structure 如何使用Selenium将后继元素计数为变量? - How could i put following-sibling elements count into variable, with Selenium? 如何导航到兄弟姐妹 <p> 使用硒的元素 - How to navigate to a sibling <p> element using selenium Selenium - 如何获得以下兄弟姐妹? - Selenium - How to get following sibling? 如何使用following-sibling全部点击<li>里面<ul java< div><div id="text_translate"><p> 我可以点击“Mentorship”li 标签,但我想点击每个 li,从“Mentorship”标签链接开始</p><pre>&lt;ul _ngcontent-cwp-c18="" class="navigation clearfix"&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current" class=""&gt;&lt;a _ngcontent-cwp-c18="" href="#/index"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18=""&gt;&lt;a _ngcontent-cwp-c18="" href="https://courses.rahulshettyacademy.com/courses"&gt;Courses&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current" class="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/mentorship"&gt;Mentorship&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/practice-project"&gt;Practice Projects&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/consulting"&gt;Consulting&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/part-time-jobs"&gt;Earn&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18=""&gt;&lt;a _ngcontent-cwp-c18="" href="http://www.qaclickacademy.com/blog/"&gt;Articles&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/about-my-mission"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li _ngcontent-cwp-c18="" routerlinkactive="current"&gt;&lt;a _ngcontent-cwp-c18="" href="#/contact-us"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;</pre><p> 这是我试过的:</p><pre> driver.get("http://www.qaclickacademy.com/"); driver.findElement(By.xpath("//ul[@class='nav navbar-nav navbar-right']//a[contains(text(),'Interview Guide')]")).click(); //mentorship driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]").click(); //practice projects driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]/following-sibling::li[1]").click(); //consulting driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]/following-sibling::li[2]").click(); //earn driver.findElementByXPath("//div[@class='nav-outer clearfix']//a[contains(text(),'Mentorship')]/following-sibling::li[3]").click();</pre><p> 请问,我如何使用以下兄弟姐妹点击每一行,从特定的一行开始?</p></div></ul></li> - How to use following-sibling to click in all <li> inside <ul JAVA 如何使用 Selenium 和 Java 识别元素 - How to identify the element using Selenium and Java 如何唯一标识硒中的元素? - How to uniquely identify an element in Selenium? 如何使用 Selenium 和 Java 构建 xpath 或 css 定位器来识别元素 - How to construct a xpath or css locator to identify the element using Selenium and Java 如何通过类名识别元素并使用Selenium和Java单击它? - How to identify an element through classname and click on it using Selenium and Java? 如何使用Java和Selenium WebDriver识别元素中的方括号是否存在 - How to identify if brackets in the element are present or not using Java and Selenium WebDriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM