Sunday 12 August 2012

Select Option from Drop down box using WebDriver

It has been quite some time, added any post related to Selenium/WebDriver. Today i will be going to write about selecting a option value from drop down box. Selenium provides a Select class to do that, it is pretty easy to use. Ok lets have one sample html for our demonstration-:






We will see now how to select options using selenium/webdriver's Select class. Below code explains how to use select class to select option from drop down box.



 Apart from the above 3 methods, there are other methods which can be used to perform other actions also.
Here is the link for Select Class methods.

Please feel free to drop a comment if you have any suggestion/comment/Issue related to the above post.

Thanks!!!

4 comments:

  1. Hi All,

    I am still facing issue after using select methods(used selectByValue("") and other above mentioned things). Below is my code:

    Select select = new Select(driver.findElement(By.xpath("//div[3]/div[1]/div[2]/div/div/div/div/div/div/div[3]/form/ul/li[2]/label/select")));
    select.selectByIndex(5);
    select.selectByValue("05");

    On using above code snippet, displayed below error:

    org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
    Command duration or timeout: 60.07 seconds
    Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_09'
    Session ID: 06c39721-cb9d-4a12-b0d5-44f43c9644f0
    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=18.0.1}]

    It will be very helpful, if someone can help me to solve this issue.

    Thanks in advance,
    Priyanka

    ReplyDelete
  2. Hello Priyanka,

    Please provide the HTML of your web page then only I can help you on this.

    Thanks
    Dibyaranjan

    ReplyDelete
  3. This sounds really helpful… very precise and interesting… pls go ahead and add more!
    Thanks!

    ReplyDelete

Related Posts

Related Posts...