List<WebElement>

12,565 views
Skip to first unread message

Richard Hunter

unread,
May 14, 2009, 10:39:22 AM5/14/09
to webdriver
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

unread,
May 14, 2009, 11:49:09 AM5/14/09
to webd...@googlegroups.com
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

Richard Hunter

unread,
May 14, 2009, 11:56:16 AM5/14/09
to webdriver
ah that was silly thanks for pointing out the missing include! I will
try your other suggestion as well that looks handy

dheeraj gupta

unread,
Apr 17, 2013, 12:10:13 PM4/17/13
to webd...@googlegroups.com
Hi Simon,

I used the below code 

WebElement element = driver.findElement(By.tagName("select")); 
Select select = new Select(element); 
select.selectByVisibleText("want this");

But in my case tag name is under the span tag.I am getting an error of " Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span""

can you please dig out the problem and provide the firm solution

krishna Murthy

unread,
Jul 1, 2013, 1:50:46 AM7/1/13
to webd...@googlegroups.com
hi....
In my project there is a list of elements and i want to mouseover on an element and here is the HTML code can someone help me how to handle this to mouse over on an element

<li class="user-itm active" rowid="dff6d0a9-8ce1-4439-b42b-905bfae79ce1">
<li class="user-itm active" rowid="fc9bb06c-d4a0-4f52-b4ce-baa37963f026">
<li class="user-itm active" rowid="fd9c63f6-fac6-45d0-a20e-bd062229a2b0">
<li class="user-itm active" rowid="c351d4b3-b224-469f-a321-4e69012208d4">
<li class="user-itm active" rowid="c4c4fcbe-9f35-41d2-a226-aae69b26278b">
<li class="user-itm active" rowid="c7b36c82-f714-4a94-a18c-14acbcd1efde">
<li class="user-itm active" rowid="c8227192-66fd-4db4-bf5e-76e1284d8d4b">
<li class="user-itm active" rowid="d522ffcd-1eb5-44fd-9eb5-f085b104fd2c">
<li class="user-itm active" rowid="dc69eab1-d9da-4e60-aa8d-58d49c7272e8">
<li class="user-itm active" rowid="ddeea9d3-c363-41d7-a21a-4376f6e0a874">
<li class="user-itm active" rowid="e5b336b3-776f-402d-9e77-fa40214d932a">
<li class="user-itm active" rowid="e89b24c0-a0fa-4f41-aa0d-9f92e9b8eb86">
<li class="user-itm active" rowid="ece32a1e-3ea6-4381-877b-2a5e2621b2df">
<li class="user-itm active" rowid="03e39e96-d5f1-4439-b750-c823060b395f">
<li class="user-itm active" rowid="1448f934-d0b2-4ab6-bfbd-e5b24614a608">
<li class="user-itm active" rowid="15255d09-58c4-4f68-9934-9b1d198dd56b">
<li class="user-itm active" rowid="18197e4b-2e8e-4e0c-a6eb-78acf54df3ca">
<li class="user-itm active" rowid="1d84163b-df71-4406-9e49-10b1ca2546c8">
<li class="user-itm active" rowid="1de7ebf4-3d3f-4a66-ad0c-9db58e1e0fa1">
<li class="user-itm active" rowid="1f98ceb5-91d9-4180-abc8-8468ff4709c5">
<li class="user-itm active" rowid="200010f8-db34-45ce-bb77-47d247a752ef">
<li class="user-itm active" rowid="22ed4cde-446f-4fb1-9a11-088a650801e4">
<li class="user-itm active" rowid="253aebd3-ee92-4e78-a817-4b739f62fa5c">
<li class="user-itm active" rowid="2878b45c-1105-45db-9bde-b7a436a1975d">
<li class="user-itm active" rowid="3000b91a-fa6e-4303-84fe-32e767532c51">
<li class="user-itm active" rowid="30af264d-2293-4583-b21d-98cd8832a4fa">
<li class="user-itm active" rowid="355cb247-0db7-4c85-91b0-892df26c826d">
<li class="user-itm active" rowid="36cbc726-6a47-4fbc-a988-b38f2b21dbb2">
<li class="user-itm active" rowid="38543adf-c741-42fa-9fb1-fa44b087524b">
<li class="user-itm active" rowid="43f0c84b-63fd-46b1-a356-932eab80bb9f">
<li class="user-itm active" rowid="461e3e6b-4d2a-443b-8c3b-c0e8093fa951">
<li class="user-itm active" rowid="47923d9b-39b6-49e7-98da-4d03a0d89d0c">
<li class="user-itm active" rowid="4c9cfc14-14a9-4b24-b9ce-b98a232087c6">
<li class="user-itm active" rowid="4fa41701-63d3-4b0b-b69e-8681f56bc2e1">
<li class="user-itm active" rowid="4faa8e5e-a426-4e01-99d2-73a04a178cfa">
<li class="user-itm active" rowid="417c62ae-3d59-45c1-a0e9-8f20ed23cc84">
<li class="user-itm active" rowid="5168ff3c-d165-4055-ba04-abf5f398ed40">
<li class="user-itm active" rowid="59ed546b-4389-4d7d-9de1-dc7cb1a8a554">
<li class="user-itm active" rowid="5ace7212-78e8-4c72-b574-d0bcc9bf92c8">
<li class="user-itm active" rowid="5c0e8ee9-bc62-4a48-be0e-ec885ada38c5">
<li class="user-itm active" rowid="5dd1f071-3501-4e28-8255-e2a63e935e5b">
<li class="user-itm active" rowid="5fb179f3-46fe-4fd8-bf00-3c14cca152cc">
<li class="user-itm active" rowid="60979402-36d8-4362-a84c-20b12e74cb21">
<li class="user-itm active" rowid="672ff9fa-bc4f-4955-a43c-bb04c131c263">
<li class="user-itm active" rowid="6c0b574c-290a-4661-9c2b-ce936f1f739f">
<li class="user-itm active" rowid="6ed8d13b-c629-4f38-8c82-e601dc932b5a">
<li class="user-itm active" rowid="6fdb7dfc-c9a3-4523-8340-a29f10c74af8">
<li class="user-itm active" rowid="884347d1-98fe-4fd3-ba8b-03a17a5dc880">
<li class="user-itm active" rowid="8c02c7fc-cf3b-4895-82f5-cc494e797632">
<li class="user-itm active" rowid="8e26e2f7-6692-4a54-8a63-8b0b9296f36b">
<li class="user-itm active" rowid="8f455497-679e-4674-98e2-b54bdd79932c">
<li class="user-itm active" rowid="94b30cbf-6fc5-4074-a81b-8219e9970c61">
<li class="user-itm active" rowid="9b3e771d-e562-4afb-9af7-b155221188dc">
<li class="user-itm active" rowid="9e6785ee-1776-4e04-bd25-dbb1af8ade20">
<li class="user-itm active" rowid="a0b8ec54-0e6b-42cc-a383-1447d3787b68">
<li class="user-itm active" rowid="a2299e0c-8a9d-4f94-8ad9-075a8c0a7e61">
<li class="user-itm active" rowid="a8859ce1-130e-4bfc-8251-0a82208fd54e">
<li class="user-itm active" rowid="7ae96a83-43dd-4594-a01f-cd3bb2e93487">
<li class="user-itm active" rowid="7df76ce8-1fe7-49d9-980e-c60989e363a7">
<li class="user-itm active" rowid="ac73ad94-bad3-443e-8baa-fcc5f5d3b279">
<li class="user-itm active" rowid="b099e2af-353d-44bd-a566-ff1aeda0a93a">
<li class="user-itm active" rowid="b3e9dfde-8a78-4509-9353-7473cf583d54">
<li class="user-itm active" rowid="b3fde957-9354-4090-861e-a32fc02ac51e">
<li class="user-itm active" rowid="b4203f9d-c8ed-4b02-b3b4-0810d4cae1ae">
<li class="user-itm active" rowid="b42c38a2-aba9-4e7a-80a4-90fdda18538b">

chirag verma

unread,
Nov 27, 2013, 6:43:32 AM11/27/13
to webd...@googlegroups.com
Hi,

Will u kindly tel me the meaning  LIst<WebElement> in below line
List<WebElement> values = dropdown.findElements(By.tagName("option"));

Regards
Chirag

Krishnan Mahadevan

unread,
Nov 28, 2013, 1:59:05 AM11/28/13
to webdriver
What exactly are you trying to look for here as an explanation ?

findElements() is designed to return back a List of WebElement which is what is being assigned to the variable "values" whose type is List<WebElement>



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

Pawan Garia

unread,
Nov 28, 2013, 6:34:55 AM11/28/13
to webd...@googlegroups.com
This means a list of type WebElement and you can iterate over this List and perform any action on particular WebElement.. 


On Wed, Nov 27, 2013 at 5:13 PM, chirag verma <chiragv...@gmail.com> wrote:

--

susanth.nair

unread,
Nov 28, 2013, 10:22:34 AM11/28/13
to webd...@googlegroups.com
can you plese share the HTML tags  . (not just the tags where u want to mouse over )

shruthi sadanala

unread,
Jan 21, 2016, 11:43:12 AM1/21/16
to webdriver
Hi,

Even am new to webdriver and java. Trying to execute below code to find the links in a particular page, and unable to proceed due to the error : "The type list is not generic; it cannot be parameterized with aurguments<webElement>"

Please provide a resolution
Thanks in advance
 public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("bhttp://www.flipkart.com/");
List<WebElement> links = driver.findElements(By.tagName("a"));
for(int i = 0;i<links.size();i++){
System.out.println(links.get(i).getText());
}
System.out.println("Total number of links = " + links.size());

Anup

unread,
Jan 21, 2016, 10:27:50 PM1/21/16
to webdriver
You need to import java.util.List and not .java.awt.List. It will solve your concern.

Regards,
Anupam Patil 
Reply all
Reply to author
Forward
0 new messages