简体   繁体   中英

Webdriver/Java/Xpath: How can I click the second “Login” link

How can I use an xpath expression to tell Selenium Webdriver to click the second "Login" link on a page?

OR:

How can I convert this to an absolute xpath

(//input[@name='commit'])[2]

Open the webpage in Chrome, Inspect the element, right click on the highlighted node and click Copy XPath.

It should look something like:

//a[text()="Login"]

//input[2] will show ALL "input" element that are the 2nd "input" of its parent eg:

 <div> <h1></h1> <input> this one is not 2nd input child</input> </div> <div2> <h1></h1> <input> this one is not 2nd input child</input> <input> this one is 2nd input child</input> </div2> 


To get the 2nd one in the order of element in the document, use "following"

Following: Selects everything in the document after the closing tag of the current node Suppose "header" is the tag right before 2 "input" tags, so the xpath for the 2nd specified input tag should be

//head/following::input[@name='commit'][2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM