下面是單選按鈕的html代碼。網格形式綁定hrml頁面中有三個單選按鈕,我想驗證是否選擇了所需的無線電按鈕。 如何使用selenium webdriver中的type - 按鈕驗證單選按鈕。
我使用的webdriver的代碼是: -
//here totalDivions is an integer value which checks for the number of radio buttons.
for(int j=1;j<=totalDivisions;j++){
String check = driver.findElement(By.xpath("//*[@id='radiogroup-1022-bodyEl']/table/tbody/tr/td["+j+"]/table/tbody/tr/td[2]/input")).getAttribute("checked");
if(check.equalsIgnoreCase("true")){
System.out.println("Checked");
}
}
我一直在使用isSelected()試過沒有用的,但是。
您好奧利弗,我沒有得到一個異常,但是當我使用isSelected()方法,它給了我一個值設置爲false,即使我看到的單選按鈕(類型=按鈕)被選中。 – stackboy 2014-11-24 15:21:27
奇怪。你的xpath表達式讓我覺得你正在使用ExtJS。你確定你正在選擇正確的輸入元素嗎? 您的代碼看起來不錯,但您也可以嘗試使用Aigrette(可在sf.net上免費獲取)測試您的應用並使用其輸入元素。 你也可以在你的收音機裏放一些獨特的類名到你的源文件中,看看生成了什麼,並找到無線電輸入元素。 – 2014-11-24 17:57:23