【问题标题】:How To Perform Multiple Radio Button Click in Selenium Webdriver如何在 Selenium Webdriver 中执行多个单选按钮单击
【发布时间】:2015-08-22 09:52:32
【问题描述】:

如何设置条件来执行多个单选按钮点击(见下图)...?

multiple radio button click

我已经尝试了几个小时,但我只有一个单选按钮点击(见附图)

single radio button click

List<WebElement> radiobutton = driver.findElements(By.xpath("//*[@type='radio']"));
    System.out.println("Total element is " + radiobutton.size());

    for (int i = 0; i < radiobutton.size(); i++) {

        // if you are getting stale element exception because of the page
        // reload
        radiobutton = driver.findElements(By.xpath("//*[@type='radio']"));

        System.out.println(radiobutton.get(i).getAttribute("value"));

        // select your radio and click to go to next page
        radiobutton.get(i).click();

        Thread.sleep(3000);

        driver.findElement(By.xpath("//input[@id='btnCheckFare']"))
                .click();

        Thread.sleep(3000);
    }

【问题讨论】:

  • 为什么不表明你已经尝试过了。
  • 一组中只能选择一个单选按钮!你的意思是一一选择吗?并发布 HTML 以获得更好的响应。
  • 您可以在此视频中看到使用人工交互的多个单选按钮youtu.be/KxydkdhNdYc?t=143

标签: java selenium selenium-webdriver radio-button


【解决方案1】:

我看过您的视频。您有多组单选按钮,您可以在每组中选择一个单选按钮。

您必须使用 2 个循环,一个用于组,一个内部循环用于组中的选择单选按钮。

如果您有编程经验,那么您可以轻松完成。否则,请提供我们可以看到此功能的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 2023-03-08
    相关资源
    最近更新 更多