java - 如何通过单击表格中的单选按钮来随机选择动态值 - 无法单击单选按钮
问题描述
我有一个表格,每次都需要通过单击单选按钮来选择动态值。
我试过的:
我首先列出了表中的单选按钮列表:
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();
}
**我的问题是它没有点击单选按钮。
任何输入都会有所帮助。我可以添加任何更多信息。**
有人可以提供意见吗?
解决方案
如前所述,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();
推荐阅读
- c# - 正则表达式找到一个不被字符包围的连字符
- mongodb - 如何在 mongodb 查询中查找和更新字段的最小值?
- windows - 通过 powershell 查询 32 位和 64 位注册表
- python - VFS 连接不存在
- angular - 如何在水平轴中间对齐引导行中的子元素?
- excel - Excel VBA 仍有注释格式问题
- clojurescript - createObjectURL 没有提供足够的参数
- tensorflow - 为什么我使用 tensorflow-gpu 和 keras 的多类分割在训练期间只使用了 2% 的 gpu?
- excel - 如何根据 Excel 或 Google 表格中其他两个字段的值更改字段值
- lua - Roblox:ServerScriptService.DamagableManager:48:尝试索引本地“鼠标”(零值)