简体   繁体   English

选择第二个下拉值Watir-Webdriver

[英]Selecting second Dropdown Value Watir-Webdriver

Design: 设计:

First Dropdown: 第一个下拉菜单:

<select id="MainContent_drpVehicleType" style="width:175px;" name="ctl00$MainContent$drpVehicleType">
<option value="">- SELECT -</option>
<option value="1" title="AUTO">AUTO</option>
<option value="2" title="HD">HD</option>
<option value="3" title="MARINE">MARINE</option>
</select> 

Second Drop Down: 第二次下拉:

<select id="MainContent_drpMake" style="width:175px;" name="ctl00$MainContent$drpVehicleType">
<option value="1" title="ACURA">ACURA</option>
<option value="2" title="ALFA ROMEO">ALFA ROMEO</option>
<option value="74" title="ALLIS CHALMERS LIFT TRUCK">ALLIS CHALMERS LIFT TRUCK</option>
<option value="75" title="ALLIS CHALMERS TRACTOR">ALLIS CHALMERS TRACTOR</option>
<option value="4" title="AMERICAN MOTORS">AMERICAN MOTORS</option
</select>

Code used for execution: 用于执行的代码:

b.select_list(:id, "MainContent_drpVehicleType").select("AUTO")

b.select_list(:id, "MainContent_drpMake").select("ACURA")

and also tried 并尝试了

`b.select_list(:id, "MainContent_drpMake").wait_until_present.option(:text, 'ACURA')`

**What my Problem is able to select "AUTO" from first dropdown and not able to select "ACURA" from second dropdown **我的问题能从第一个下拉列表中选择“自动”,而不能从第二个下拉列表中选择“ ACURA”

Error While Executing: 执行时出错:

C:/Ruby193/menu.rb:23:in `<main>': 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir-webdriver/el
ements/select.rb:218:in `no_value_found': "ACURA" not found in select list (Wati
r::Exception::NoValueFoundException)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir
-webdriver/elements/select.rb:152:in `rescue in select_by_string'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir
-webdriver/elements/select.rb:149:in `select_by_string'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir
-webdriver/elements/select.rb:131:in `select_by'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.2/lib/watir
-webdriver/elements/select.rb:64:in `select'
        from C:/Ruby193/menu.rb:23:in `<main>'**

It sounds like your second dropdown is populated after the first dropdown value is selected. 听起来好像在选择第一个下拉列表值之后填充了第二个下拉列表。 In that case, you need to wait for the second dropdown list to be populated (rather than for the second dropdown to appear). 在这种情况下,您需要等待第二个下拉列表被填充(而不是第二个下拉列表出现)。

You can wait for the specific option to appear and then set it by doing: 您可以等待特定选项出现,然后通过以下操作进行设置:

#The option element that you want:
option = b.select_list(:id, "MainContent_drpMake").option(:text => "ACURA")

#Wait for the option to appear
option.wait_until_present

#Set the option
option.select

Or if you want to do it on one line, you can use when_present : 或者,如果您想一行执行,则可以使用when_present

b.select_list(:id, "MainContent_drpMake").option(:text => "ACURA").when_present.select

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM