如何使用Selenium按值查找单选按钮元素?

Joe*_*Joe 12 selenium selenium-ide selenium-chromedriver selenium-webdriver

到现在为止我只是喜欢:

val radioButton4: WebElement = driver.findElement(By.id("FieldsubCode2"))

radioButton4.click
Run Code Online (Sandbox Code Playgroud)

但现在我想按值找到元素,这个值:

在此输入图像描述

所以我想去:

val radioButton4: WebElement = driver.findElement(By.value("3.2"))


radioButton4.click
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Bha*_*Vre 12

如果您只想按价值找到然后使用,

driver.findElement(By.xpath("//input[@value='3.2']"));
Run Code Online (Sandbox Code Playgroud)


Ter*_*nja 9

driver.findElement(By.xpath("//input[@name='buttonName' and @value='3.2']"));
Run Code Online (Sandbox Code Playgroud)


小智 5

driver.FindElement(By.cssSelector(input[type='radio'][value='3.2']));
Run Code Online (Sandbox Code Playgroud)