views:

82

answers:

2

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

A: 

You did not tell what the problem is, this is not enough:

none of these are giving me what i am looking for

This should enter CA into text field:

browser.text_field(:id => "ext-comp-1005").set("CA")

If it is entering text into wrong text field, change :id => "ext-comp-1005".

If it is entering text into the correct text field, but list of states does not appear, you probably have to fire some javascript event. Take a look at How to find out which JavaScript events fired? question.

Željko Filipin
Thanks for replying to my question.Actually that works perfectly fine for text_field but in my case I have drop down list with auto complete, so when i used the above method, It is setting the value to be CAA which defeats the purpose. I tried using div but no help. I tired using the div but that is not working either.Here is the code I am using @browser.text_field(:id,"ext-comp-1055").set "C" and once the drop down shows states only starting with C I am using @browser.div(:id => "ext-gen336", :index => 2).click Please let me know if i am doing something wrong.thanks!
QA Geeks
I still do not understand the problem.
Željko Filipin
A: 

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.

JEH