我是watir webdriver和ruby的新手。在我的第一个scipt中,我试图输入一个搜索字符串并触发看起来像按钮的单击操作但是通过元素检查不适合作为按钮。插入搜索字符串后,我的watir脚本无法单击搜索按钮。
None of the following three options worked.
browser.a(:id=> "search0_SearchIcon").submit
browser.button(:id=> "search0_SearchIcon").submit
browser.div(:id=> "header").div(:class=> "head-container").div(:class=> "search-field").button(:class => "rb-search-button js-rb-search-button").click
*******Test target code is listed below****
</div>
<div class="search-field">
<input accesskey="s" aria-autocomplete="list" aria-haspopup="true" autocomplete="off" class="js-rb-search-input" id="rbSearchInput" name="rbSearchInput" role="textbox" type="text" value="" />
<a id="search0_SearchIcon" class="rb-search-button js-rb-search-button"></a>
<form id="GeneralSearchForm" method="GET" action="/Search">
<input name="query" type="hidden" id="rbSearchInputHidden" class="js-rb-search-input-hidden" />
</form>
</div>
</div>
************
答案 0 :(得分:2)
“按钮”有两个方面:
a
或link
方法。click
方法(而非submit
方法)。根据您的个人喜好,以下任何一项都应点击“按钮”:
browser.a(:id => "search0_SearchIcon").click
或
browser.link(:id => "search0_SearchIcon").click