Home > Net >  Ruby Watir Form Pulldown Not Found
Ruby Watir Form Pulldown Not Found

Time:10-14

Does anybody have any insight as to how to trigger a selection in a pulldown using Watir? I can't seem to get this to find that first field. I've tried class (deprecated apparently), id, and name.

require 'webdrivers/chromedriver'
require 'open-uri'
require 'json'

Selenium::WebDriver::Chrome.path = '/Applications/RF_Utilities/Google Chrome.app/Contents/MacOS/Google Chrome'
url = 'https://www.finditatmpg.com/Default.aspx'

a = Watir::Browser.new :chrome, headless: false
a.goto url
#   a.select(id: 'dpdCemetery_Input').select('Beechwood')  
a.select(name: 'dpdCemetery').select('Beechwood')                       # doesn't work
puts "cemetery selected"                                  # a marker

a.text_field(id: 'txtSurname').set 'Smith'                          # this works if set first
puts "last name selected"                                 # a marker

a.text_field(id: 'txtFirstname').set 'John'
puts "first name selected"                              # a marker

a.button(id: 'btnSearch_input').click                       # submit

The error:

timed out after 5 seconds, waiting for false condition on #<Watir::Select: located: false; {:name=>"dpdCemetery", :tag_name=>"select"}> (Watir::Wait::TimeoutError)

Update: Here is the copied syntax of the form:

<div id="dpdCemetery" class="RadComboBox RadComboBox_Bootstrap" style="width:300px;white-space:normal;">
  <!-- 2021.1.119.45 --><table summary="combobox" style="border-width:0;border-collapse:collapse;width:100%">
    <tbody><tr>
      <td class="rcbInputCell rcbInputCellLeft" style="width:100%;">
        <input name="dpdCemetery" type="text" class="rcbInput radPreventDecorate" id="dpdCemetery_Input" value="Select a Cemetery" autocomplete="off">
      </td>
      <td class="rcbArrowCell rcbArrowCellRight">
        <a id="dpdCemetery_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a>
      </td>
    </tr>
  </tbody></table><div class="rcbSlide" style="z-index:6000;display:none;"><div id="dpdCemetery_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Bootstrap "><div class="rcbScroll rcbWidth"></div></div></div><input id="dpdCemetery_ClientState" name="dpdCemetery_ClientState" type="hidden" autocomplete="off">
</div>

CodePudding user response:

The problem is that these are not "real" HTML Select/Option element dropdowns, so you can't use the Select class. The tag name is a div not a select.

You'll need to use something like:

a.div(name: 'dpdCemetary').click
a.li(text: /Beechwood/).click

CodePudding user response:

Solved:

a.text_field(name: 'dpdCemetery').set('Beechwood')

Seems it behaves like a text field. JS provides the dropdown list. I was under the impression Watir could handle that sort of thing.

  • Related