Sasa.D Sasa.D - 1 year ago 67
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){



But Boolean returning me only true value...

Answer Source

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("//id of undo-checkout"));
            }catch (Exception e) {
            WebElement e1 = driver.findElement("//id of checkout-and-edit""));

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download