"元素目前不可见,因此可能无法与"的Watir

时间:2015-03-19 08:31:50

标签: watir watir-webdriver

在测试脚本中执行代码时遇到问题。相同的代码在irb中执行正常

@browser.div(:class=>/DownArrowButton/).when_present.click #works fine, dropdown
popup = @browser.div(:id=>'pgObjectSelector_Popover')
popup.text_fields(:id=>/dijit_form_TextBox_/).select{|s| s.visible?}[0].when_present.set('ethernet')

设置密钥时,窗口小部件会因错误而关闭:

  

元素目前不可见,因此可能无法与之互动   [remote server] file:/// C:/ Users / suchanna / AppData / Local / Temp / webdriver-profile20150319-30448-a96p5v / extensions / fxdriver @ googl   ecode.com/components/command-processor.js:8991:in`fxdriver.preconditions.visible'

请帮助我解决上述问题

HTML:



    <div id="pgObjectSelector_Popover" class="xwtPopover dijitTooltipDialog xwt_BasePickerPopover dijitTooltipABLeft dijitTooltipBelow" wairole="presentation" widgetid="pgObjectSelector_Popover" style="top: 0px; display: none;">
        <div class="dijitTooltipContainer" data-dojo-attach-event="onkeypress: _onKey" wairole="dialog" waistate="labelledby-pgObjectSelector_Popover_title" data-dojo-attach-point="_outsideContainer" style="">
            <table class="xwtPopoverMenuBar" cellspacing="0" cellpadding="0" data-dojo-attach-point="menuBar" wairole="presentation"></table>
            <div class="xwtPopoverPadding" data-dojo-attach-point="_paddingContainer">
                <div class="dijitTooltipContents dijitTooltipFocusNode" tabindex="-1" data-dojo-attach-point="_scrollBox" style="overflow-x: hidden;">
                    <table class="xwtPopoverTable" wairole="presentation">
                        <tbody>
                            <tr>
                                <td wairole="presentation">
                                    <div class="xwtPopoverContainer" wairole="presentation" tabindex="-1" data-dojo-attach-point="containerNode">
                                        <div id="dijit_layout_BorderContainer_0" class="dijitBorderContainerNoGutter dijitContainer dijitLayoutContainer" widgetid="dijit_layout_BorderContainer_0" style="padding: 0px; width: 275px; height: 300px;">
                                            <div id="dijit_layout_ContentPane_1" class="dijitContentPane dijitBorderContainerNoGutter-child dijitBor…nerNoGutterPane dijitAlignCenter dijitContentPaneSingleChild" widgetid="dijit_layout_ContentPane_1" style="left: 0px; top: 0px; position: absolute; width: 275px; height: 300px;">
                                                <div id="pgObjectSelector_osInstance" class="xwtobjectselector" minheight="100" minwidth="220" data-dojo-attach-point="osNode" widgetid="pgObjectSelector_osInstance" style="cursor: default; width: 273px; height: 298px;">
                                                    <div id="xwt_widget_objectselector__Titlebar_0" class="xwtOsTitlebar" minwidth="100" data-dojo-attach-point="titleBar" widgetid="xwt_widget_objectselector__Titlebar_0"></div>
                                                    <div class="xwtobjectselectorcontents xwtOSDataReady" data-dojo-attach-point="osContents">
                                                        <div class="xwtObjectSelectorToolbars" data-dojo-attach-point="toolbars">
                                                            <div id="xwt_widget_objectselector__ObjectSelectorToolbar_0" class="xwtOsToolbar" data-dojo-attach-point="ButtonToolbar" minwidth="100" data-dojo-type="xwt.widget.toolbar.LayoutToolbar" widgetid="xwt_widget_objectselector__ObjectSelectorToolbar_0" style="display: none;"></div>
                                                            <div id="xwt_widget_filtertoolbar_FilterToolbar_0" class="xwtFilterToolbar" widgetid="xwt_widget_filtertoolbar_FilterToolbar_0" style="width: 273px;">
                                                                <div class="xwtFilterbarLeft" data-dojo-attach-point="SearchLeftGroup"></div>
                                                                <div class="xwtFilterbarCenter" data-dojo-attach-point="SearchCenterGroup">
                                                                    <div class="xwtFilterSearchIcon icon-cisco-search" title="Search" tabindex="0" data-dojo-attach-point="searchButton">
                                                                        <div class="xwt-ButtonSearchTextHighContrast" data-dojo-attach-point="searchTextHighCont"></div>
                                                                        <span class="xwtFilterSearchText" data-dojo-attach-point="searchText"></span>
                                                                    </div>
                                                                    <span class="dijit dijitReset dijitInline xwtFilterDownButton xwtFilterDownIcon xwtFilterbarDropdownOff" widgetid="dijit_form_DropDownButton_3">
                                                                        <span class="dijitReset dijitInline dijitButtonNode" data-dojo-attach-point="_buttonNode" data-dojo-attach-event="ondijitclick:__onClick"></span>
                                                                        <input class="dijitOffScreen" type="button" aria-hidden="true" role="presentation" data-dojo-attach-point="valueNode" data-dojo-attach-event="onclick:_onClick" tabindex="-1" value=""></input>
                                                                    </span>
                                                                    <div id="widget_dijit_form_TextBox_1" class="dijit dijitReset dijitInline dijitLeft xwtFilterSearchBox dijitTextBox" role="presentation" widgetid="dijit_form_TextBox_1" style="width: 185px;">
                                                                        <div class="dijitReset dijitInputField dijitInputContainer">
                                                                            <input id="dijit_form_TextBox_1" class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textbox,focusNode" tabindex="0" value=""></input>
                                                                            <span class="dijitPlaceHolder dijitInputField">

                                                                                Search All

                                                                            </span>
                                                                        </div>
                                                                    </div>
                                                                    <div class="xwtFilterClearIcon" data-dojo-attach-event="ondijitclick: _clearIconClicked" tabindex="0" data-dojo-attach-point="closeButton"></div>
                                                                    <div class="xwtClear"></div>
                                                                </div>
                                                                <div class="xwtFilterbarRight" data-dojo-attach-point="SearchRightGroup"></div>
                                                                <div class="xwtAdvFilterButton" data-dojo-attach-point="advancedFilter"></div>
                                                                <div class="xwtClear"></div>
                                                            </div>
                                                            <div id="dijit_layout_ContentPane_0" class="dijitContentPane xwtOsScopeTabs" dolayout="true" minwidth="100" data-dojo-type="dijit/layout/ContentPane" data-dojo-attach-point="scopeTabs" widgetid="dijit_layout_ContentPane_0"></div>
                                                            <div id="xwt_widget_objectselector__SelectionDisplayBar_0" class="xwtOsSelectionBar" minwidth="100" data-dojo-attach-point="selectionBar" widgetid="xwt_widget_objectselector__SelectionDisplayBar_0" style="width: 268px;"></div>
                                                        </div>
                                                        <div id="dijit_layout_StackContainer_0" class="xwtobjectselectorview dijitStackContainer dijitContainer dijitLayoutContainer xwtOSDataReady xwtOsStackContainer" dolayout="true" data-dojo-attach-point="containerNode" widgetid="dijit_layout_StackContainer_0" style="width: 273px; height: 214px;"></div>
                                                    </div>
                                                    <div class="resizeHandleBoth" data-dojo-attach-point="resizeHandleAP" style="display: none;"></div>
                                                    <div class="xwtOsFooter"></div>
                                                    <div class="xwtOsLeftShadow"></div>
                                                    <div class="xwtOsRightShadow"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="xwtPopoverFooter" data-dojo-attach-point="footer"></div>
        </div>
        <!--

         Added connector attach point 

        -->
        <div class="dijitTooltipConnector" data-dojo-attach-point="connector" wairole="presentation" style="left: 8px;"></div>
        <div class="xwtPopoverLoader icon-spinner icon-spin" data-dojo-attach-point="loader" style="bottom: 139.333px; left: 153.5px; display: none;"></div>
    </div>

</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

好的,首先,如果您需要在此字段中设置任何文字,可以使用以下内容div

id => 'pgObjectSelector_Popover'使用JavaScript,使用execute_script@browser.execute_script("document.getElementById('pgObjectSelector_Popover').style.display = 'block';"),之后,此弹出窗口只有一个text_field,您可以这样做:@browser.div(pgObjectSelector_Popover).text_field.set 'ethernet' < / p>

其次,

@browser.div(:class=>/DownArrowButton/).when_present.click 
@browser.div(:id=>'pgObjectSelector_Popover').text_field.set 'ethernet'