首页 > 解决方案 > 如何通过单击表格中的单选按钮来随机选择动态值 - 无法单击单选按钮

问题描述

我有一个表格,每次都需要通过单击单选按钮来选择动态值。

我试过的:

我首先列出了表中的单选按钮列表:

List<WebElement> radiobuttonoptions = driver.findElements(By.xpath("(//table[contains(@class,'mat-table cdk-table')])

[2]//following::span[contains(@class,'mat-radio-outer-circle')]"));

然后我列出了该列的列表 - 我已经按照我的需要这样做了

在 OPTION 列中选择任何以 OPT 开头的选项

这是列表:

 List<WebElement> section = driver.findElements(By.xpath("//tbody[@role='rowgroup']/tr/td[2]"));
          

现在如果从部分列表中获取文本并检查列

有文字:opt

 for(WebElement optinselection:optselection)
                {
                    
                     
{
Then i randomly go and click on the radio button
 {

                    Random random = new Random();
                    int index = random.nextInt(radiobuttonoptions.size());
                    radiobuttonoptions.get(index).click(); 

}

**我的问题是它没有点击单选按钮。

任何输入都会有所帮助。我可以添加任何更多信息。**

有人可以提供意见吗?

标签: javaseleniumselenium-webdriverautomationcucumber

解决方案


如前所述,xpath//input[contains(@id,'mat-radio')]可以单击单选按钮。如果input标签在 内span,那么过程应该有点像这样。

radiobuttonoptions = driver.findElements("xpath for `span` that contains `VESE`")
Random random = new Random();
int index = random.nextInt(radiobuttonoptions.size());
radiobuttonoptions[index].#find element by tag name `input` .click();

推荐阅读