简体   繁体   中英

Selenium: How to select nth button using the same class name

I am trying to select the 3rd button using the css class "btnProceed"

    <input type="button" class="btnProceed" value=" " onclick="SecuritySubmit(false,'https://somewebsite.com/key=xxyyzz');return false;">

My code is as follows:

    WebElement query_enquirymode = driver.findElement(By.className("btnProceed"));
    query_enquirymode.click();

I can only select the 1st element using "btnProceed"

Is there a way to select the 3rd button?

Like this:

List<WebElement> buttons = driver.findElements(By.className("btnProceed"));
WebElement query_enquirymode = buttons.get(2);
query_enquirymode.click();

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