为了账号安全,请及时绑定邮箱和手机立即绑定

在python中使用硒选择复选框

在python中使用硒选择复选框

温温酱 2022-06-28 17:26:04
我想在 python 中使用 selenium 选择一个复选框。以下是复选框的 HTML。将鼠标悬停在复选框上时,跨度元素会突出显示HTML<div id="rc-anchor-container" class="rc-anchor rc-anchor-normal rc-anchor-light">    <div id="recaptcha-accessible-status" class="rc-anchor-aria-status" aria-hidden="true">Recaptcha requires verification. </div>    <div class="rc-anchor-error-msg-container" style="display:none"><span class="rc-anchor-error-msg" aria-hidden="true"></span></div>    <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" role="checkbox" aria-checked="false" id="recaptcha-anchor" tabindex="0" dir="ltr" aria-labelledby="recaptcha-anchor-label"><div class="recaptcha-checkbox-border" role="presentation"></div><div class="recaptcha-checkbox-borderAnimation" role="presentation"></div><div class="recaptcha-checkbox-spinner" role="presentation"></div><div class="recaptcha-checkbox-spinnerAnimation" role="presentation"></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>    <div class="rc-anchor-normal-footer">        <div class="rc-anchor-logo-portrait" aria-hidden="true" role="presentation">            <div class="rc-anchor-logo-img rc-anchor-logo-img-portrait"></div>            <div class="rc-anchor-logo-text">reCAPTCHA</div>        </div>我正在尝试以下代码,但它给出了以下异常selenium.common.exceptions.NoSuchElementException
查看完整描述

1 回答

?
繁花如伊

TA贡献2012条经验 获得超12个赞

这是一个 recaptha 的东西 .. 它不像页面中的普通元素


您必须使用 selenium 导航到验证码框架..然后您可以处理复选框元素..


为此,您需要先保存主窗口句柄,以便在完成 recaptcha 后返回它


# save the main window handle

mainwindow = browser.current_window_handle


# get the recapthca iframe then navigate to it

frame = browser.find_element_by_tag_name("iframe")  

browser.switch_to.frame(frame)


# now you can access the checkbox element 

browser.find_element_by_id("recaptcha-anchor").click()


# navigate back to main window

browser.switch_to.window(mainwindow)

有关如何处理 recaptcha 挑战的更多信息,请查看此链接


查看完整回答
反对 回复 2022-06-28
  • 1 回答
  • 0 关注
  • 113 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号