简体   繁体   中英

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.

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. So it is hard to suggest and it will be nice if you will provide the url of the page to experiment with.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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