2016-04-01 9 views
0

私はフレームワークに取り組んでいますと、次のといないの結果しようとしている:あなたはラジオボタンが選択されているかどうかを検証したいときSelenium Java、複数のラジオボタンが選択されているかどうかを確認するにはどうすればいいですか?

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())); 
    } 
} 

答えて

0

こんにちは、次に型ラジオを持つ任意の入力タグが持っていることを注意してくださいと選択された隠し属性値ラジオボタンが選択されている場合はその値はTrueで、それ以外の場合は値はnullです。したがって、これに基づいて、どのラジオボタンが選択されているかを簡単に識別できます。同じものの実施例を見つける

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(); 
      } 
     } 
関連する問題