【发布时间】:2021-11-06 10:30:20
【问题描述】:
我有一个包含许多框架的网页,其中一个包含一个我想单击的按钮!附言: 我不知道如何使用 iframe 列表并选择目标的索引,但我有一些关于如何创建 XPath 的信息。
html代码:
<iframe title="Test reCAPTCHA" src="https://www.google.com/recaptcha/api2/bframe?hl=fr&v=wxAi4AKLXL2kBAvXqI4XLSWS&k=6Ld-Kg8UAAAAAK6U2Ur94LX8-Agew_jk1pQ3meJ1&cb=qrwicghkkby6" name="c-ewoxmbtw42b9" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox" style="width: 400px; height: 580px;"></iframe>
代码:
driver = webdriver.Chrome(executable_path=driver_path)
driver.get("https://online.vfsglobal.dz/Global-Appointment/")
driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
driver.find_element_by_class_name("recaptcha-checkbox-border").click()
time.sleep(3)
driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_xpath('//iframe[@name="c-ewoxmbtw42b9"]')) // here the issue
driver.find_element_by_id("recaptcha-audio-button").click()
driver.switch_to.default_content()
【问题讨论】: