0

問題のウェブサイト: http://gis.nyc.gov/doitt/nycitymap/template?applicationName=ZOLA

現在のコード:

  $browser = Watir::Browser.new
  $browser.goto "http://gis.nyc.gov/doitt/nycitymap/template?applicationName=ZOLA"
  $browser.span(:id, "zolaDisclaimerButton").when_present.click
  $browser.span(:id, "dijit_layout_ContentPane_0_button_title").click

上記はサイトに移動し、免責事項に同意して、右側の [場所を検索] をクリックします。ページにはコンボボックスとしてドロップダウン ボックスがあり、デフォルト以外のものを選択する必要があります。これは選択リストではないため、select_list(blahblah).select("text") は使用できません。このタイプのコードを操作するにはどうすればよいですか?

ウェブサイトのセクションは次のとおりです。

<div title="Search Type"><div id="widget_wm_widget_SimpleSelect_0" class="dijit dijitReset dijitInlineTable dijitLeft formField dijitTextBox dijitComboBox" lang="" wairole="combobox" dojoattachpoint="comboNode" role="combobox" dir="ltr" style="vertical-align: baseline ! important;" widgetid="wm_widget_SimpleSelect_0" aria-expanded="false"><div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" dojoattachevent="onmousedown:_onArrowMouseDown" wairole="presentation" role="presentation" dojoattachpoint="downArrowNode"><input class="dijitReset dijitInputField dijitArrowButtonInner" type="text" wairole="presentation" readonly="" tabindex="-1" value="▼ " role="presentation"></input></div><div class="dijitReset dijitValidationContainer"><input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" type="text" wairole="presentation" readonly="" tabindex="-1" value="Χ " role="presentation"></input></div><div class="dijitReset dijitInputField dijitInputContainer"><input id="wm_widget_SimpleSelect_0" class="dijitReset dijitInputInner" type="text" waistate="haspopup-true,autocomplete-list" wairole="textbox" dojoattachpoint="textbox,focusNode" dojoattachevent="onkeypress:_onKeyPress,compositionend" autocomplete="off" role="textbox" aria-haspopup="true" aria-autocomplete="list" aria-invalid="false" tabindex="0" aria-required="true" value="Address" aria-owns="wm_widget_SimpleSelect_0_popup"></input></div></div><br></br><img class="wmHorizontalLine" src="/doitt/webmap/js/dojo/resources/blank.gif"></img></div></div>

(Firefox の Web 開発者から引用。その方が読みやすいかもしれません)

4

1 に答える 1

1

入力は以下のとおりです。1 つはテキストボックス、もう 1 つは矢印ボタンです。

<div id="widget_wm_widget_SimpleSelect_0" class="dijit dijitReset dijitInlineTable dijitLeft formField dijitTextBox dijitComboBox" lang="" wairole="combobox" dojoattachpoint="comboNode" role="combobox" dir="ltr" style="vertical-align: baseline ! important;" widgetid="wm_widget_SimpleSelect_0" aria-expanded="false">
    <div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" dojoattachevent="onmousedown:_onArrowMouseDown" wairole="presentation" dojoattachpoint="downArrowNode" role="presentation">
         <input class="dijitReset dijitInputField dijitArrowButtonInner" type="text" wairole="presentation" readonly="" tabindex="-1" value="▼ " role="presentation"/>
    </div>
    <div class="dijitReset dijitInputField dijitInputContainer">
        <input id="wm_widget_SimpleSelect_0" class="dijitReset dijitInputInner" type="text" waistate="haspopup-true,autocomplete-list" wairole="textbox" dojoattachpoint="textbox,focusNode" dojoattachevent="onkeypress:_onKeyPress,compositionend" autocomplete="off" role="textbox" aria-haspopup="true" aria-autocomplete="list" aria-invalid="false" tabindex="0" aria-required="true" value="Address" aria-owns="wm_widget_SimpleSelect_0_popup">
    </div>
</div>

ドロップダウン リストは DOM の下部にある div ですが、存在しますが、ページが読み込まれると非表示になります。

<div id="widget_wm_widget_SimpleSelect_0_dropdown" class="dijitPopup dijitComboBoxMenuPopup" style="visibility: hidden; top: -9999px; z-index: 1000; left: 1609.3px;" role="presentation" dijitpopupparent="wm_widget_SimpleSelect_0">
    <ul id="wm_widget_SimpleSelect_0_popup" class="dijitReset dijitMenu dijitComboBoxMenu" style="top: 0px; overflow: hidden; width: 200px; height: 88px;" tabindex="-1" dojoattachevent="onmousedown:_onMouseDown,onmouseup:_onMouseUp,onmouseover:_onMouseOver,onmouseout:_onMouseOut" dir="ltr" widgetid="wm_widget_SimpleSelect_0_popup">
        <li id="wm_widget_SimpleSelect_0_popup_prev" class="dijitMenuItem dijitMenuPreviousButton" wairole="option" dojoattachpoint="previousButton" role="option" style="display: none;">Previous choices</li>
        <li id="wm_widget_SimpleSelect_0_popup0" class="dijitReset dijitMenuItem" role="option">Address</li>
        <li id="wm_widget_SimpleSelect_0_popup1" class="dijitReset dijitMenuItem" role="option">Borough / Block / Lot</li>
        <li id="wm_widget_SimpleSelect_0_popup2" class="dijitReset dijitMenuItem" role="option">Intersection</li>
        <li id="wm_widget_SimpleSelect_0_popup3" class="dijitReset dijitMenuItem" role="option">Place of Interest</li>
        <li id="wm_widget_SimpleSelect_0_popup_next" class="dijitMenuItem dijitMenuNextButton" wairole="option" dojoattachpoint="nextButton" role="option" style="display: none;">More choices</li>
    </ul>
</div>

したがって、ロジックは、矢印ボタンをクリックし、それら<li>が表示されるのを待ってから、表示されて<li>いる .

$browser.element(:css, "#widget_wm_widget_SimpleSelect_0 .dijitArrowButton").click

# find option by css selector or xpath for only visible ones
# e.g. clicking `Place of Interest`
$browser.element(:css, ".dijitComboBoxMenuPopup[style*='visibility: visible;'] #wm_widget_SimpleSelect_0_popup3").click
于 2013-07-31T01:23:18.693 に答える