Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
gkpandi
Active particpant
Active particpant
Posts : 14
Join date : 2013-05-23

How to select an item from the Drop Down combo thru' selenium web driver Empty 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.

How to select an item from the Drop Down combo thru' selenium web driver EDGChHJtOOB1pDNGZKk5Wo6ZFmR1P3oeMgGwET8Cxfny2+SvuzPAAAAAElFTkSuQmCC

Please guide how can I solve this problem?

Thanks in advance
avatar
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

How to select an item from the Drop Down combo thru' selenium web driver Empty 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)
avatar
gkpandi
Active particpant
Active particpant
Posts : 14
Join date : 2013-05-23

How to select an item from the Drop Down combo thru' selenium web driver Empty 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 ]
avatar
tarun3kumar
Master
Master
Posts : 186
Join date : 2012-02-14
http://seleniumtests.com

How to select an item from the Drop Down combo thru' selenium web driver Empty 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
avatar
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

How to select an item from the Drop Down combo thru' selenium web driver Empty 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.
Sponsored content

How to select an item from the Drop Down combo thru' selenium web driver Empty Re: How to select an item from the Drop Down combo thru' selenium web driver

Back to top
Permissions in this forum:
You cannot reply to topics in this forum