Selenium:如何使用相同的类名选择第 n 个按钮 [英] Selenium: How to select nth button using the same class name

查看:50
本文介绍了Selenium:如何使用相同的类名选择第 n 个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 css 类btnProceed"选择第三个按钮

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

我的代码如下:

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

我只能使用btnProceed"选择第一个元素

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

有没有办法选择第三个按钮?

Is there a way to select the 3rd button?

推荐答案

像这样:

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

这篇关于Selenium:如何使用相同的类名选择第 n 个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆