Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use select list in selenium?

Tags:

java

selenium

I'm trying to select an element from a select list in selenium using java with WebDriver - based syntax.

I've got the select list by

    elements = driver.findElements(By.xpath("//form[@action='inquiry/']/p/select[@name='myselect']"));
    if (elements.size() == 0) {
        return false;
    }
    if (guests != null) {
        //what do I do here?
    }

How do I do that?

like image 718
Arsen Zahray Avatar asked Oct 08 '11 08:10

Arsen Zahray


1 Answers

A little side note which applies to Java:

In my case, when I was writing the test according the example of @nilesh, I got a strange error, that the constructor is invalid. My import was:

import org.openqa.jetty.html.Select;

If you happen to have similar errors, you have to correct that import to this:

import org.openqa.selenium.support.ui.Select;

If you use this second import, everything will work.

like image 84
Pavel Janicek Avatar answered Sep 20 '22 14:09

Pavel Janicek