Selenium webdriver :- How to verify that a particular value is not present in the dropdown

Answered

I am testing a scenario where I have to verify that value :- India is not present in the dropdown

Steps :-

  1. Launch http://newtours.demoaut.com/

2. Enter username as test1 and password as test1

3. In the Departing From dropdown I have to verify if India is in the list or not.

 

 

 

 

Add Comment
  • 2 Answer(s)
    Best answer

    Use below code:

     

    Select selDepartingFrom=new Select(element);

    List<WebElement> lstDepartingFrom=selDepartingFrom.getOptions();

    boolean flag=false;
    for(WebElement e : lstDepartingFrom){
    if(e.getText().equals(“India”)){
    System.out.println(“India is present in Departing From dropdown list.”);
    flag=true;
    break;
    }
    }
    if(flag==false){
    System.out.println(“India is not present in Departing From dropdown list.”);
    }

    Train Answered on May 16, 2017.
    Add Comment

    you can use isdisplayed inside try catch.

    Try it out, it should work 🙂

    Supporter Answered on May 8, 2017.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.