!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: List<WebElement>  (Read 1235 times)

Richard Hunter

  • Web User
List<WebElement>
« on: March 27, 2012, 09:06:17 PM »
Hi,
 I am very new to webdriver (started yesterday) so I apologise for the
 basic question.
 
I am trying to select a value from a drop down list on a webpage, and
 having a search on this group and a the interwe I have found the
 following code (or similar) in several places:
 
 WebElement select = driver.findElement(By.tagName("select"));
                  List<WebElement> options = select.findElements(By.tagName
 ("option"));
                  for (WebElement option : options) {
                    if ("want this".equals(option.getValue())) {
                      option.setSelected();
                      break;
                    }
                  }
 
However before I try and change it to use the drop down I have in mind
 I always get the error 'List cannot be resolved'.
 
Is there another way of doing this, or have I missed the obvious
 (which would bring the tally up for the day to be about 15)
 
Thanks in advance
 
Richard

Simon Stewart

  • Web User
Re: List<WebElement>
« Reply #1 on: March 27, 2012, 09:06:32 PM »
Hi Richard,
 Welcome to the group!
 
The "List" referred to is Java's "java.util.List" class: you'll need
 that in the import statements at the top of your java code. We also
 use generics, so you'll need to be using Java 5 or above for this to
 compile.
 
You may find that the "Select" class in the webdriver-support.jar is
 useful to you. From your example, it could be used like this:
 
WebElement element = driver.findElement(By.tagName("select"));
 Select select = new Select(element);
 select.selectByVisibleText("want this");
 
The fully qualified name you'll need in the import statement is
 "org.openqa.selenium.support.ui.Select".
 
Regards,
 
Simon
 
On Thu, May 14, 2009 at 3:39 PM, Richard Hunter
 

- Show quoted text -

Richard Hunter

  • Web User
Re: List<WebElement>
« Reply #2 on: March 27, 2012, 09:06:41 PM »
ah that was silly thanks for pointing out the missing include! I will
 try your other suggestion as well that looks handy
 On May 14, 4:49 pm, Simon Stewart <simon.m.stew...@gmail.com> wrote:
 

- Show quoted text -

Selenium Webdriver

Re: List<WebElement>
« Reply #2 on: March 27, 2012, 09:06:41 PM »

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
2245 Views
Last post February 23, 2012, 01:21:06 PM
by Mirko Nasato
10 Replies
1960 Views
Last post February 23, 2012, 01:43:53 PM
by James Strachan
2 Replies
3912 Views
Last post March 28, 2012, 03:30:27 PM
by Danny Leblond
7 Replies
1919 Views
Last post March 28, 2012, 09:26:55 PM
by Simon Stewart
4 Replies
1613 Views
Last post April 12, 2012, 04:55:07 PM
by Luke Inman-Semerau
4 Replies
2682 Views
Last post March 26, 2013, 02:18:27 AM
by Andrew_
1 Replies
790 Views
Last post August 14, 2013, 11:36:49 AM
by Andrew_