问题
In the website I am trying to fill some fields, there is a checkbok that I need to click to add the check mark in it
<div class="rc-anchor-content"><div class="rc-inline-block"><div class="rc-anchor-center-container"><div class="rc-anchor-center-item rc-anchor-checkbox-holder"><span class="recaptcha-checkbox goog-inline-block recaptcha-checkbox-unchecked rc-anchor-checkbox recaptcha-checkbox-expired" role="checkbox" aria-checked="false" id="recaptcha-anchor" dir="ltr" aria-labelledby="recaptcha-anchor-label" aria-disabled="false" tabindex="0"><div class="recaptcha-checkbox-border" role="presentation" style=""></div><div class="recaptcha-checkbox-borderAnimation" role="presentation" style=""></div><div class="recaptcha-checkbox-spinner" role="presentation" style="transform: rotate(180deg);"></div><div class="recaptcha-checkbox-spinnerAnimation" role="presentation" style=""></div><div class="recaptcha-checkbox-checkmark" role="presentation"></div></span></div></div></div><div class="rc-inline-block"><div class="rc-anchor-center-container"><label class="rc-anchor-center-item rc-anchor-checkbox-label" aria-hidden="true" role="presentation" id="recaptcha-anchor-label"><span aria-live="polite" aria-labelledby="recaptcha-accessible-status"></span>I'm not a robot</label></div></div></div>
Using selenium in VBA I tried the following
.FindElementByCss("div.recaptcha-checkbox-border").Click
and also I tried
.FindElementByCss("span.recaptcha-checkbox").Click
But I got an error at this line
Here's the link of the website to see the whole HTML https://www.moj.gov.kw/AR/E-Gov/Pages/eServices01.aspx
回答1:
To click()
on the element, as the desired element is within an <iframe>
so you have to:
- Induce a waiter and switch to the desired frame.
- Induce a waiter for the desired element to be clickable.
You can use the following solution:
.SwitchToFrame.FindElementByXPath("//iframe[contains(@src, 'recaptcha') and not(@title='recaptcha challenge')]", timeout:=10000) .FindElementByCss("div.recaptcha-checkbox-checkmark").Click
You can find similar discussions in:
- How to click on the reCaptcha using Selenium and Java
- Find the reCAPTCHA element and click on it — Python + Selenium
Here you can find a relevant discussion on Ways to deal with #document under iframe
来源:https://stackoverflow.com/questions/57074490/css-selector-for-recaptcha-checkbok-using-selenium-and-vba-excel