![](/img/trans.png)
[英]Can't access text of an element in an array using PageObject and Watir
[英]Can't access checkbox with watir
當我嘗試單擊復選框時出現錯誤
browser.checkbox(:id, 'AgreeToProceedWithPersonalData').click
Element is not clickable at point (314.5, 448). Other element would receive the click: <label for="AgreeToProceedWithPersonalData"></label>
當我點擊下面的元素時,我打開了協議頁面。
browser.label(:for, 'AgreeToProceedWithPersonalData').click
如何設置復選框而不打開協議?
<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&targetElement=AgreeToProceedWithPersonalData" class="moddialog">Read the agreement</a> </label> <span class="field-validation-valid" data-valmsg-for="AgreeToProceedWithPersonalData" data-valmsg-replace="true"></span> </div>
很多時候,開發人員喜歡通過在標准 html 元素之上分層來使事情變得漂亮,而驅動程序不喜歡這樣。
請不要過度使用它,因為這對大多數事情來說都不是好習慣,但在這種情況下,我發現自己需要這樣做:
browser.checkbox(id: 'AgreeForBKIRequest').fire_event :click
如果 fire_event 不工作,很可能頁面上有一些非常自定義的 javascript。 所以很難提出建議,如果你能提供頁面的 url 來進行試驗,那就太好了。
但是,您可以在沒有保證的情況下嘗試這樣的建議(只是猜測)
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.