Java 布尔检查后单击单选按钮
我正在查看页面上的单选按钮 我找到了页面上的所有按钮,如果它们是假的,我想点击它们 我真的很难点击它…如果结果是假的 我怎样才能点击它 -----------------------------------------------------------------------------Java 布尔检查后单击单选按钮,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在查看页面上的单选按钮 我找到了页面上的所有按钮,如果它们是假的,我想点击它们 我真的很难点击它…如果结果是假的 我怎样才能点击它 ----------------------------------------------------------------------------- 我已经附上了我当前的代码和html页面 List<WebElement> elementxb1 = driver.findElements(By.xpath("//input[@name='co
我已经附上了我当前的代码和html页面
List<WebElement> elementxb1 = driver.findElements(By.xpath("//input[@name='contractPeriod']"));
for(int i11 = 0 ; i11< elementxb1.size() ; i11++){
boolean vapval2b = elementxb1.get(i11).findElement(By.xpath("//input[@name='contractPeriod']")).isSelected();
if(vapval2b)
{
System.out.println("Yes Button is selected ? : " + vapval2b);
}
else
{
System.out.println("No Button is not selected, click on it. ? :" + vapval2b);
// click on the radio button here.
}
}
List elementxb1=driver.findElements(By.xpath(//input[@name='contractPeriod']);
对于(inti11=0;i11
HTML:
-----------------------------------------------------------------------------
[uib typeahead popup].c-下拉菜单{显示:块;可见性:可见;不透明度:1;}@charset“UTF-8”;[ng \:斗篷],[ng斗篷],[x-ng-斗篷],.ng斗篷,.x-ng-斗篷,.ng隐藏:非(.ng隐藏动画){display:none!重要;}ng \:表单{display:block;}.ng动画填充{visibility:hidden;}.ng定位{position absolute;}
文件
VAP建议
保修建议
VAP关键资料单张
VAP采购决策
保修购买决策
-->
2018年1月5日,星期五
24小时合同前审查期内的财务合同订立表:是否
试试这个:
List<WebElement> elementxb1 = driver.findElements(By.xpath("//input[@name='contractPeriod']"));
for (WebElement element : elementxb1){
boolean vapval2b = element.isSelected();
if(vapval2b)
{
System.out.println("Yes Button is selected ? : " + vapval2b);
}
else
{
System.out.println("No Button is not selected, click on it. ? :" + vapval2b);
// click on the radio button here.
if(element.isDisplayed())
element.click();
else{((JavascriptExecutor)driver).executeScript("arguments[0].click();",element);
}
}
}
List elementxb1=driver.findElements(By.xpath(//input[@name='contractPeriod']);
for(WebElement:elementxb1){
布尔值vapval2b=element.isSelected();
if(vapval2b)
{
System.out.println(“选择是按钮?:”+vapval2b);
}
其他的
{
System.out.println(“没有选择任何按钮,点击它.?:”+vapval2b);
//单击此处的单选按钮。
if(element.isDisplayed())
元素。单击();
else{((JavascriptExecutor)driver.executeScript(“参数[0]。单击();”,元素);
}
}
}
编辑1:
List<WebElement> elementxb1 = driver.findElements(By.xpath("//input[@name='contractPeriod']"));
for(int i11 = 0 ; i11< elementxb1.size() ; i11++){
elem = elementxb1.get(i11).findElement(By.xpath("//input[@name='contractPeriod']"));
boolean vapval2b = elem.isSelected();
if(vapval2b)
{
System.out.println("Yes Button is selected ? : " + vapval2b);
}
else
{
System.out.println("No Button is not selected, click on it. ? :" + vapval2b);
// click on the radio button here.
if(elem.isDisplayed())
elem.click();
else{((JavascriptExecutor)driver).executeScript("arguments[0].click();",elem);
}
}
List elementxb1=driver.findElements(By.xpath(//input[@name='contractPeriod']);
对于(inti11=0;i11
int i11=0;i11
您可以在这里使用foreach结构WebElement-element:elementxb1
修改了第2行:“for(WebElement-element:elementxb1){”它运行,但在“click()”上,它作为“element not visible”失败?从上面我的答案中尝试Edit1。很多时候,复选框不可见,您可以使用javascript executor单击它。更新了答案,请检查。非常好的解决方案。我只是在else语句中使用了“((JavascriptExecutor)driver)。executeScript(“参数[0]。单击();”,elem);”,效果很好。
List<WebElement> elementxb1 = driver.findElements(By.xpath("//input[@name='contractPeriod']"));
for(int i11 = 0 ; i11< elementxb1.size() ; i11++){
elem = elementxb1.get(i11).findElement(By.xpath("//input[@name='contractPeriod']"));
boolean vapval2b = elem.isSelected();
if(vapval2b)
{
System.out.println("Yes Button is selected ? : " + vapval2b);
}
else
{
System.out.println("No Button is not selected, click on it. ? :" + vapval2b);
// click on the radio button here.
if(elem.isDisplayed())
elem.click();
else{((JavascriptExecutor)driver).executeScript("arguments[0].click();",elem);
}
}