【问题标题】:How to choose the right iframe with webdriver?如何使用 webdriver 选择合适的 iframe?
【发布时间】:2020-03-31 19:26:50
【问题描述】:

我正在尝试编写单击此网络验证码的按钮的代码,我需要什么代码才能按下它? 网址:https://www.google.com/recaptcha/api2/demo

我试过了:

   //Driver.Manage().Timeouts().ImplicitWait(80, TimeUnit.SECONDS);
   IWebElement iframeSwitch = 
Driver.FindElement(By.XPath("/html/body/section/div/div/section/div/article/div/div[2]/form/table/tbody/tr/td[1]/div/div/div/iframe"));
   Driver.SwitchTo().Frame(iframeSwitch);
   Driver.FindElement(By.CssSelector("div[class=recaptcha-checkbox-checkmark]")).Click();

截图: enter image description here

【问题讨论】:

  • 您是否要在 recaptcha 中选中复选标记?

标签: c# selenium captcha


【解决方案1】:

这是您可以用来点击复选框的代码。

需要导入(用于显式等待)

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

选中复选框的代码:

frame = WebDriverWait(driver,30).until(EC.presence_of_element_located((By.CSS_SELECTOR,"iframe[name^='a']")))
driver.switch_to.frame(frame)
driver.find_element_by_css_selector('.recaptcha-checkbox').click()

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-22
  • 2017-03-30
  • 2016-04-03
  • 1970-01-01
相关资源
最近更新 更多