我正在研究一个框架,并尝试了以下几点,但没有取得结果:
List<WebElement> rows = EarningNormal.oRdioList;
java.util.Iterator<WebElement> i = rows.iterator();
while(i.hasNext()) {
WebElement ContribIDYES = i.next();
//System.out.println(sitcodes.getText());
if(ContribIDYES.isSelected()){
TestDriver.globalProps.getHtmlReport().writeHTMLReport("Contribution ID Formulas must be set to Yes as default", "Contribution IDs must be set to YES ", "All Contribution IDs must be YES","Contribution ID's are set to YES" , "PASS", "Done");
}
else{
TestDriver.globalProps.getHtmlReport().writeHTMLReport("Contribution ID Formulas must be set to Yes as default", "Contribution IDs must be set to YES ", "All Contribution IDs must be YES", "Contribution ID's are NOT seto to YES as default", "FAILED",TestDriver.comUtil.getImageFileLoc(TestDriver.globalProps.getWebDriver()));
}
}发布于 2016-04-01 16:27:46
嗨,当你想验证一个单选按钮是否被选中时,请注意任何带有类型单选的输入标签都有一个名为 selected 的隐藏属性值,如果选择了一个单选按钮,那么它的值是= True,如果不是,则它的值是= null,因此在此基础上,您可以很容易地识别选择哪个单选按钮或不选择.below,找到一个相同的工作示例。
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("C:\\Users\\rajnish\\Desktop\\myradio.html");
// working with radio buttons
// first take all the radio buttons inside a list like below
List<WebElement> myradioloc = driver.findElements(By.xpath("//*[@type='radio']"));
// apply the for loop to identify/ verify if a radio button is selected or not
for(int i=0;i<myradioloc.size();i++){
System.out.println("attribut value Selected of radio button is : " + myradioloc.get(i).getAttribute("selected"));
// if radio button is selected then value of selected attribute is True else null
if( myradioloc.get(i).getAttribute("selected").equals("null")){
// as if loop will only run when value of selected attribute is null
// i.e only when radio button is not selected
myradioloc.get(i).click();
}
}https://stackoverflow.com/questions/36360280
复制相似问题