Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

View previous topic View next topic Go down

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

Post by gkpandi on 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

gkpandi
Active particpant
Active particpant

Posts : 14
Join date : 2013-05-23

Back to top Go down

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

Post by tarun3kumar on 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)

_________________
Thanks
Tarun K
Free Selenium Training

tarun3kumar
Master
Master

Posts : 186
Join date : 2012-02-14

http://seleniumtests.com

Back to top Go down

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

Post by gkpandi on 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 ]

gkpandi
Active particpant
Active particpant

Posts : 14
Join date : 2013-05-23

Back to top Go down

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

Post by tarun3kumar on Wed Jun 05, 2013 1:20 pm

It would work if element has "select" tag

_________________
Thanks
Tarun K
Free Selenium Training

tarun3kumar
Master
Master

Posts : 186
Join date : 2012-02-14

http://seleniumtests.com

Back to top Go down

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

Post by mail2prassad on 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.

mail2prassad
Amateur
Amateur

Posts : 41
Join date : 2013-06-05

Back to top Go down

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

Post by Sponsored content Today at 7:28 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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