0
我正在java中使用webdriver實現方法'getValue'(返回類型需要的是字符串)來獲取複選框/ radioButton/textBox的值如下圖所示:方法'getValue'獲取webdriver中的複選框/ radioButton/textBox的值
try {
element=driver.findElement(By.xpath(target));
BoolResult = element.isSelected();
if(BoolResult==true) {
result="Radio Button/textbox Selected";
return result;
} else if(BoolResult==false){
result="Radio Button/textbox Not Selected";
return result;
} else {
}
} catch(Exception e2) {
}
try {
element=driver.findElement(By.xpath(target));
result = element.getAttribute("value");
log.info("The value of the target is : " + result);
} catch (Exception e) {
log.debug(e);
return result;
}
的單選按鈕,上面的工作正常,但對於文本框,它要去BoolResult ==假條件,並說「單選按鈕/文本框未選擇」,而我期待它去到下一個try塊並執行'element.getAttribute(「value」)'。
有人可以幫忙嗎?
這是工作完全正常。我在這裏找到的新點是通過使用'element.getAttribute(「type」)'來確定元素是否爲複選框/收音機/文本框。它讓我的任務變得簡單..謝謝你.. – Sree
太棒了,很高興幫助:) –