我是网络驱动程序的新手 我想从下拉菜单中选择启用和禁用选项之间的选项。 例如......将2选项作为
答案 0 :(得分:0)
I am assuming that u have something like below html code written for option u have give:
<option value="0" ></option>
<option value="1" >check-out-and-edit</option>
<option value="2" disabled>undo-checkout</option>
The first try to fetch the list of options you have, then for each option in the list try to find the one having disable as attribute associated with it.
For your reference I have given some sample code below.
Hope this help.
`List<WebElement> opts = temp.findElements(By.xpath(".//option"));
WebElement dis_elem;
for (WebElement opt : opts){
if(dis_elem = opt.getAttribute("disabled")!= null)
{
if(dis_elem.getText().equalsIgnoreCase("check-out-and-edit")
{
//Put the logic u want to execute in case undo-checkout option is eanble.
}
Else if if(dis_elem.getText().equalsIgnoreCase("undo-checkout")
{
// Put the logic u want to execute in case check-out-and-edit option is eanble.
}
}
}`
Else please post the HTML code of your page.
答案 1 :(得分:0)
首先使用以下代码获取undo-checkout的id ..
String e =driver.findElement(By.linkText("Undo Checkout")).getAttribute("id");
一旦你得到它然后把条件放在try和catch块中 如...
try {
WebElement e = driver.findElement(By.id("//id of undo-checkout"));
undocheckout();
}catch (Exception e) {
WebElement e1 = driver.findElement(By.id("//id of checkout-and-edit""));
checkoutandedit();
}
如果第一个存在,则尝试执行,否则catch将执行...