简体   繁体   English

无法使用 watir 访问复选框

[英]Can't access checkbox with watir

When I'm trying to click checkbox I getting an error当我尝试单击复选框时出现错误

browser.checkbox(:id, 'AgreeToProceedWithPersonalData').click

Element is not clickable at point (314.5, 448). Other element would receive the click: <label for="AgreeToProceedWithPersonalData"></label>

And when I click at element below I getting agreement page opened.当我点击下面的元素时,我打开了协议页面。

browser.label(:for, 'AgreeToProceedWithPersonalData').click

How do I can set checkbox and do not open agreement?如何设置复选框而不打开协议?

 <div class="checkbox"> <input data-val="true" data-val-mustbetrue="Ваше согласие необходимо для продолжения" data-val-required="The I agree to proceed personal data field is required." id="AgreeToProceedWithPersonalData" name="AgreeToProceedWithPersonalData" type="checkbox" value="true" autocomplete="off" checked="checked"> <label for="AgreeToProceedWithPersonalData">I agree to proceed personal data. <a href="/client/Questionnaire/Agreement?type=Private&amp;targetElement=AgreeToProceedWithPersonalData" class="moddialog">Read the agreement</a> </label> <span class="field-validation-valid" data-valmsg-for="AgreeToProceedWithPersonalData" data-valmsg-replace="true"></span> </div>

Often times developers like to make things pretty by layering things on top of standard html elements, and the driver doesn't like that.很多时候,开发人员喜欢通过在标准 html 元素之上分层来使事情变得漂亮,而驱动程序不喜欢这样。

Please don't over-use this, as it is not good practice for most things, but in situations like this I find myself needing to do:请不要过度使用它,因为这对大多数事情来说都不是好习惯,但在这种情况下,我发现自己需要这样做:

browser.checkbox(id: 'AgreeForBKIRequest').fire_event :click

Most probably there is something very custom with javascript on the page if fire_event is not working.如果 fire_event 不工作,很可能页面上有一些非常自定义的 javascript。 So it is hard to suggest and it will be nice if you will provide the url of the page to experiment with.所以很难提出建议,如果你能提供页面的 url 来进行试验,那就太好了。

However you could try such suggestion with no guaranty (just guess)但是,您可以在没有保证的情况下尝试这样的建议(只是猜测)

browser.execute_script("window.stop")# That will stop all the scripts on the page. May be usefull may be not
browser.execute_script("document.getElementById('AgreeToProceedWithPersonalData').click();")# That will perform click using pure javascript

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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