Webdriver - Drop down select values. (IE Driver)
There is no direct method to choose/click the values from the drop down.
I have used following code to select the list values. Also attaching the screen shot of the list box HTML for better understanding.
String UOMCode = "A1";
driver.findElement(By.xpath("//select[@id='ddlUOM']/option[@value='"+UOMCode+"']")).click();
Also read following post
http://bharath-marrivada.blogspot.in/2012/03/webdriverselenium2-listboxselectdropdow.html
----
There is no direct method to choose/click the values from the drop down.
I have used following code to select the list values. Also attaching the screen shot of the list box HTML for better understanding.
String UOMCode = "A1";
driver.findElement(By.xpath("//select[@id='ddlUOM']/option[@value='"+UOMCode+"']")).click();
Also read following post
http://bharath-marrivada.blogspot.in/2012/03/webdriverselenium2-listboxselectdropdow.html
----
well you need to create object for "Select" and use it to select value from drop down.
ReplyDeleteNot required. Above code works perfectly fine to me.
ReplyDeleteThis examples is too complex and require to write tricky xpath. Better to use
ReplyDeleteSelect options = Select(driver.findElement(By.id('ddlUOM'));
options.selectByValue('UOMCode');
than better to move WebElement into the PageObject to make code more reusable.
Hello Andrew,
ReplyDeleteYour code will not working for my application, so I have taken different approach.
please share your approach as above one is not working for my application.
ReplyDelete