Sasa.D Sasa.D - 16 days ago 5
Java Question

Choose between Enabled and Disables option from dropdown in selenium webdrivers

I am New to Web-drivers
I want to choose an option between enabled and disabled option from dropdown menu..
For Example..having 2 option as


  1. Here i cannot click on **check-out-and-edit** as **undo-checkout is visible**
    2.If this condition i continue with my code



So the scenario is..
I cannot click on check-out-and-edit option if undo-checkout is visible..
So i want the code sample for this condition such that..
If my undo-checkout is visible then i click on undo-check and then on check-out-Edit option butttttt if my check-out-and-edit is all ready visible then i should continue with my code..

My Sample code..

boolean c1 = driver.findElement(By.linkText("Undo Checkout")).isEnabled();
if(c1== true){

}
else{

}


But Boolean returning me only true value...

Answer

First get id for undo-checkout using below code..

String e =driver.findElement(By.linkText("Undo Checkout")).getAttribute("id");

once you get it then put condition in try and catch block as...

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

if 1st is present try will execute otherwise catch will execute...

Comments