Search code examples
watirfirewatir

Firewatir: Firewatir scripts to select a item from the drop down


I am new to Watir automation testing and would like to get some help for the drop down.On our website we have a state drop down where you enter the first letter of the state (in my example C for California) and it narrows it down to the all states starting with C. Once you have the list you need to click on the correct state. But I am having difficulties selecting the correct state.

(Below is the html from our website:


<div class="x-form-field-wrap x-trigger-wrap-focus" id="ext-gen202" style="width: 166px;">
<input type="hidden" id="entityStateCode" name="entityStateCode" value="">
<input type="text" id="ext-comp-1005" autocomplete="off" size="24" class=" x-form-text x-form-field x-form-focus">

I used the following to automate the scenario but none of these are giving me what i am looking for:

@browser.text_field(:id,"ext-comp-1005").value=("CA")

@browser.text_field(:id,"ext-comp-1005").set("CA")

@browser.text_field(:id=> "ext-comp-1055",:index => 5).set "CA"

I really appreciate that if you can point me to the right direction.

Thanks


Solution

  • I ran into a similar situation before. In my situation there was a TABLE inside the DIV which had a separate row for each item in the dynamic drop down. So, if that's the case for you then you would need to use something like this to access the items:

    @browser.text_field(:id,"ext-comp-1055").set "C"
    table = @browser.div(:id, "ext-gen336").table(:index, 1)
    puts "First entry value: #{table[1][1].text}"
    table[2][1].click  # second entry
    

    Try printing out the HTML for the DIV at runtime to see the specifics of what you need to interact with if that doesn't work.