简体   繁体   中英

Watir automation: how to select item from combo list

I need to select one of the items from combo list. Could you help? In Development tool items declared as:

<div class="x-combo-list-inner" id="ext-gen146" style="width: 298px; height: 62px;">
    <div class="x-combo-list-item">Select..
    <div class="x-combo-list-item">Benefits Quick Case
    <div class="x-combo-list-item x-combo-selected">Time Off Quick Case</
</div>

Code:

topic_dropdown_box.click

sleep 7

def combo_list_Timeoff.click

def combo_list_Timeoff; @browser.iframe(:class, 'ext-shim').div(:css, 'x-combo-list-item x-combo-selected').div(:text, 'Time Off Quick Case');end

I'm not certain I know what you are looking for here. #select_list will only work on select / option html elements, so likely you will need to open the drop down before clicking the option you want.

Depending on how this is implemented in your application, you will likely need to do something along the lines of:

combo_list = @browser.div(id: "ext-gen146")
combo_list.click
combo_list.div(text: "Time Off Quick Case").when_present.click

It appears that 'ext-gen146' is dynamically generated, in which case you could do something like: (id: /ext-gen\\d\\d\\d/)

UPDATE: The class selector can only take one class as an argument. Try:

@browser.iframe(class: 'ext-shim').div(css: '.x-combo-list-item.x-combo-selected').div(text: 'Time Off Quick Case')

actually, so long as the text is present, you shouldn't even need the intermediary div: @browser.iframe(class: 'ext-shim').div(text: 'Time Off Quick Case')

Try this:

[browser].select_list(:id, "[id tag]").select_value("[value to be selected]")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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