- gkpandiActive particpant
- Posts : 14
Join date : 2013-05-23
How to select an item from the Drop Down combo thru' selenium web driver
Mon Jun 03, 2013 6:52 pm
Hi Friends,
I'm using Selenium WebDriver 2.0 and I need a script for selecting an item from the drop down combo box.
I got the (x)path information when I recorded my webpage using Selenium IDE and my code is the following:
driver.findElement(By.xpath("//div[@id='j_idt51:country']/div[2]/span")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")).click();
When I run this code from Eclipse, system is not selecting the SECOND element from the drop down combo instead it is retaining the first element. See this screen shot where I'm unable to select USA item from the combo box thru' the above script.
Please guide how can I solve this problem?
Thanks in advance
I'm using Selenium WebDriver 2.0 and I need a script for selecting an item from the drop down combo box.
I got the (x)path information when I recorded my webpage using Selenium IDE and my code is the following:
driver.findElement(By.xpath("//div[@id='j_idt51:country']/div[2]/span")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")).click();
When I run this code from Eclipse, system is not selecting the SECOND element from the drop down combo instead it is retaining the first element. See this screen shot where I'm unable to select USA item from the combo box thru' the above script.
Please guide how can I solve this problem?
Thanks in advance
Re: How to select an item from the Drop Down combo thru' selenium web driver
Tue Jun 04, 2013 10:52 am
You can use Select class to select element from drop down in WebDriver -
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/Select.html#selectByVisibleText(java.lang.String)
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/Select.html#selectByVisibleText(java.lang.String)
- gkpandiActive particpant
- Posts : 14
Join date : 2013-05-23
Re: How to select an item from the Drop Down combo thru' selenium web driver
Tue Jun 04, 2013 11:25 am
I tried with 'Select' class like this.
Select sel = new Select (driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")));
sel.click();
But it is not working instead it is displaying the following error message in the console.
[ Element should have been select but was span ]
Select sel = new Select (driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")));
sel.click();
But it is not working instead it is displaying the following error message in the console.
[ Element should have been select but was span ]
Re: How to select an item from the Drop Down combo thru' selenium web driver
Wed Jun 05, 2013 1:20 pm
It would work if element has "select" tag
- mail2prassadAmateur
- Posts : 41
Join date : 2013-06-05
Re: How to select an item from the Drop Down combo thru' selenium web driver
Wed Jun 05, 2013 11:12 pm
Does driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")) refer to the correct element.
Try to print / debug
driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")).getAttribute("innerHTML")';
and see whether it got the required element in it.
Try to print / debug
driver.findElement(By.xpath("//div[@id='j_idt51:country_panel']/ul/li[2]")).getAttribute("innerHTML")';
and see whether it got the required element in it.
- Urgent-how can i select and click on items present in combo box/drop down list box
- selecting search item values in drop down using selenium webdriver
- Select the “back” button of the Firefox browser to right click and Select the Option from the right click Menu in Selenium Web Driver - Java
- To select an element inside a folder in a Tree structure UI uisng selenium web driver calls
- cant able to select drop down otions
Permissions in this forum:
You cannot reply to topics in this forum