Java 当有两个或三个单选按钮时,如何使用selenium选择单选按钮
我正在寻找使用java编写的selenium代码,该代码介绍如何在表单中有多个单选按钮时选择特定的单选按钮 对于一个单选按钮,硒是可以的。单击(“radio1”),但在上述情况下 即,我正在从excel表格中读取数据Java 当有两个或三个单选按钮时,如何使用selenium选择单选按钮,java,selenium,radio-button,Java,Selenium,Radio Button,我正在寻找使用java编写的selenium代码,该代码介绍如何在表单中有多个单选按钮时选择特定的单选按钮 对于一个单选按钮,硒是可以的。单击(“radio1”),但在上述情况下 即,我正在从excel表格中读取数据 请在这方面帮助我您可以有多个同名单选按钮。因此,您需要通过id属性(每个元素必须是唯一的)或基于value属性(我只能假设它是不同的)进行选择。。。或者通过位置索引(但这是一种有点脆弱的方法) e、 用这样的东西 selenium.click("id=idOfItem"); sel
请在这方面帮助我您可以有多个同名单选按钮。因此,您需要通过id属性(每个元素必须是唯一的)或基于value属性(我只能假设它是不同的)进行选择。。。或者通过位置索引(但这是一种有点脆弱的方法) e、 用这样的东西
selenium.click("id=idOfItem");
selenium.click("xpath=//input[@value='Blue']");//select radio with value 'Blue'
您可以有多个同名单选按钮。因此,您需要通过id属性(每个元素必须是唯一的)或基于value属性(我只能假设它是不同的)进行选择。。。或者通过位置索引(但这是一种有点脆弱的方法) e、 用这样的东西
selenium.click("id=idOfItem");
selenium.click("xpath=//input[@value='Blue']");//select radio with value 'Blue'
使用selenium.check(“name=value=”)代码>
请注意,所有按钮的
都是相同的,但
会有所不同。使用selenium。检查(“name=value=”)代码>
// get all the radio buttons by similar id or xpath and store in List
List<WebElement> radioBx= driver.findElements(By.id("radioid"));
// This will tell you the number of radio button are present
int iSize = radioBx.size();
//iterate each link and click on it
for (int i = 0; i < iSize ; i++){
// Store the Check Box name to the string variable, using 'Value' attribute
String sValue = radioBx.get(i).getAttribute("value");
// Select the Check Box it the value of the Check Box is same what you are looking for
if (sValue.equalsIgnoreCase("Checkbox expected Text")){
radioBx.get(i).click();
// This will take the execution out of for loop
break;
}
}
请注意,
对于所有按钮都是相同的,但是
会有所不同。//通过类似的id或xpath获取所有单选按钮并存储在列表中
// get all the radio buttons by similar id or xpath and store in List
List<WebElement> radioBx= driver.findElements(By.id("radioid"));
// This will tell you the number of radio button are present
int iSize = radioBx.size();
//iterate each link and click on it
for (int i = 0; i < iSize ; i++){
// Store the Check Box name to the string variable, using 'Value' attribute
String sValue = radioBx.get(i).getAttribute("value");
// Select the Check Box it the value of the Check Box is same what you are looking for
if (sValue.equalsIgnoreCase("Checkbox expected Text")){
radioBx.get(i).click();
// This will take the execution out of for loop
break;
}
}
List radioBx=driver.findElements(By.id(“radiod”);
//这将告诉您存在的单选按钮的数量
int iSize=radioBx.size();
//迭代每个链接并单击它
for(int i=0;i
//通过类似的id或xpath获取所有单选按钮并存储在列表中
List radioBx=driver.findElements(By.id(“radiod”);
//这将告诉您存在的单选按钮的数量
int iSize=radioBx.size();
//迭代每个链接并单击它
for(int i=0;i