Ng Zhong Qin
Ng Zhong Qin

Reputation: 1261

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?

Upvotes: 2

Views: 6546

Answers (1)

asgoth
asgoth

Reputation: 35829

Like this:

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

Upvotes: 8

Related Questions