Watir-webdriver : How to select an option from the list

1,308 views
Skip to first unread message

watir webdriver

unread,
May 17, 2013, 11:58:11 AM5/17/13
to watir-...@googlegroups.com
Hi,

In my application I've to select an option from the list.I tried as below but its not selecting the option:

@browser.select_list(:name => "siteName").select "ccfashion"

HTML code:
<select id="site" onchange="$('input[name=switchToSite]').val(true); $('#switchSiteShopAdminForm').submit();" name="siteName">
<option value="burton">burton</option>
<option value="burtoneu">burtoneu</option>
<option value="cathkidston">cathkidston</option>
<option value="ccfashion">ccfashion</option>
<option value="chemistdirect">chemistdirect</option>
<option value="cloggs">cloggs</option>
<option value="coggles">coggles</option>
<option value="colorway">colorway</option>
<option value="coopersofstortford">coopersofstortford</option>
<option value="cottontraders">cottontraders</option>
<option value="crewclothing">crewclothing</option>
<option value="cultura">cultura</option>
</select>

Error message :
 "ccfashion" not found in select list (Watir::Exception::NoValueFoundException)

Thanks in-advance.

watir webdriver

unread,
May 17, 2013, 12:07:53 PM5/17/13
to watir-...@googlegroups.com


On Friday, May 17, 2013 4:58:11 PM UTC+1, watir webdriver wrote:
Hi,

In my application I've to select an option from the list.I tried as below but its not selecting the option:

@browser.select_list(:name => "siteName").select "ccfashion"
@browser.select_list_element(:name => "siteName").option(:value, 'ccfashion')

Dan

unread,
May 17, 2013, 1:45:54 PM5/17/13
to watir-...@googlegroups.com
You may need a when_present because if that list is being populated via some other selection or ajax it might not be there when you're trying to select it.
 
@browser.select_list(:name => "siteName").when_present.select "ccfashion"

Chuck van der Linden

unread,
May 17, 2013, 4:37:49 PM5/17/13
to watir-...@googlegroups.com


On Friday, May 17, 2013 10:45:54 AM UTC-7, Dan wrote:
You may need a when_present because if that list is being populated via some other selection or ajax it might not be there when you're trying to select it.
 
@browser.select_list(:name => "siteName").when_present.select "ccfashion"
 
+1 for that idea.  I've had to do that a bunch on sites that use ajax calls to create the lists.  However in this case the error was not that it could not find the list, but the option, so we may need to wait for the option to be present, not the list.  I think this might work for that

  @browser.select_list(:name => "siteName").option("ccfashion").when_present.select


A lot of times an indication this is needed is if a line of code works fine from IRB (because by the time you type in the code, the list is likely populated) but not when run in your script.   If you don't like IRB you could try something like this, to see if the item appears in the list over time

  10.times do
    puts @browser.select_list(:name => "siteName").include?("ccfashion")
    sleep 1
  end

If that does not work, is there more than one list?  maybe you are finding a list that does not include that option?

 puts @browser.select_lists(:name => "siteName").count   # should be 1 if there is only one list with that name

Since the list has an ID that should be unique of the name is not, so you could try

@browser.select_list(:id => "site").select "ccfashion"

watir webdriver

unread,
May 20, 2013, 7:42:20 AM5/20/13
to watir-...@googlegroups.com
Thanks experts it worked now...


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/EcMT07GzGrs/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages