.setSelect() does not trigger onchange event

137 views
Skip to first unread message

WDTester

unread,
Oct 26, 2011, 3:08:24 PM10/26/11
to webdriver
I'm trying to select a "group" value from a
dropdown and once that value is selected, it should trigger the
onchange event to show the child elements in that group. Below are
the
page's html code and my webdriver code. I'm executing this in IE.

Html code:
<select id="airspace_id0" onchange="updateAirspace(0,this);"
name="airspace_id">
<option value="0"> -- Airspace/Group -- </option>
<optgroup label="Groups">
<option value="g35167">RANGE ONE</option>
<option value="g35172">RANGE THREE</option>
<optgroup label="Airspaces">
// a bunch of child elements
</select>


Webdriver code:
WebElement select = driver.findElement(By.xpath("//
select[@id='airspace_id0']/optgroup[1]"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options) {
if("RANGE ONE".equals(option.getText())){
String airspace_temp = "RANGE ONE";
option.setSelected();
System.out.println(airspace_temp);
}



Aniket Gadre

unread,
Oct 27, 2011, 12:15:46 PM10/27/11
to webd...@googlegroups.com
As I was told few days back, SetSelected method is deprecated. Try.Click. Not sure how it didn't throw any exception when you used setSelected




--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.




--
Best Regards,
Aniket Gadre
Senior SME - Test Automation
Amdocs , Pune.
E-add: aniket...@amdocs.com

Daniel Wagner-Hall

unread,
Oct 31, 2011, 3:14:26 AM10/31/11
to webd...@googlegroups.com
setSelected is no longer supported; if you can use it, it sounds like
you're using an old version, and should upgrade (there have been a lot
of bugfixes). After upgrading,tTry option.click()

Better yet, check out the Select support class [1] which is designed
for just this purpose:

Select select = new
Select(driver.findElement(By.xpath("//select[@id='airspace_id0']/optgroup[1]")));
select.selectByVisibleText("RANGE ONE");

1: http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/Select.html

Reply all
Reply to author
Forward
0 new messages