因此,我们的页面中包含以下代码:
<div class="toggle-wrapper">
<input id="HasRegistration_true" class="registration_required toggle" type="radio" value="True" name="HasRegistration" data-val-required="The HasRegistration field is required." data-val="true">
<label for="HasRegistration_true" class="">On</label>
<input id="HasRegistration_false" class="registration_required toggle" type="radio" value="False" name="HasRegistration" checked="checked">
<label class="checked" for="HasRegistration_false">Off</label>
</div>这是两个单选按钮。“开”和“关”。“‘Off”是默认值。
使用Watir-webdriver和Ruby,我们想要选择'On‘单选按钮。我们这样做:
browser.radio(:id => "HasRegistration_true").set但在这样做的过程中,我们会得到以下错误:
`WebElement.clickElement': Element cannot be scrolled into view:[object HTMLInputElement] (Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)我们知道Selenium 2会将页面滚动到元素,所以向下滚动是没有用的。我们总是使用watir-webdriver和ruby的最新版本。
我们不能更改页面的HTML,因为我们是QA工程师。
发布于 2014-04-15 21:13:35
这里有两个对我有效的解决方案:
有一个名为watir-scroll的Ruby gem可以工作。
然后
require 'watir-scroll'
browser.scroll.to browser.radio(:id, "HasRegistration_true")如果你不想添加一个gem,我的同事建议了一些令人惊讶的(对我来说)与上面的代码具有相同效果的东西:
browser.radio(:id, "HasRegistration_true").focus
browser.radio(:id, "HasRegistration_true").set在我的代码中,".focus“直接滚动到以前不可见的元素。它可能也适用于你。
发布于 2013-03-13 20:06:29
首先,尝试使用XPATH定位元素:
browser.element(:xpath, "//input[@id='HasRegistration_true']").click或
或者,如果它是您正在尝试定位的隐藏元素,那么您最好使用CSS。下载firefox的firebug插件并复制元素的CSS路径。
它应该是这样的:
browser.element(:css => "the CSS path you have copied from Firebug").click两个人中的一个应该为你做这件事!!
祝你好运!
发布于 2013-03-14 09:02:16
您可以通过执行一些javascript来动态操作html,从而使无线元素可设置。要在页面上执行javascript,请执行以下操作:@browser.execute_script("your javascript here")
我使用了类似下面的javascript来从标签标签中剥离类,这使得它远离了我试图处理的输入标签的方式,因为我遇到了一个Chrome特定的问题。execute_script("$(\"label.classname\").removeClass(\"classname inline\")")
https://stackoverflow.com/questions/14970251
复制相似问题