我正在尝试用selenium选择一个元素,但我无法选择它。我尝试用xpath,css和执行javascript来选择它来点击它但没有运气。有什么想法吗?
我能够使用katalon ide自动化插件和javascript控制台选择它,这让我相信有一种方法可以做到这一点。
以下是代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get(url="https://www.google.com/recaptcha/api2/demo")
driver.switch_to.frame(0)
driver.find_element(By.CSS_SELECTOR, "div.recaptcha-checkbox-checkmark").click()
driver.switch_to.default_content()
driver.switch_to.frame(1)
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR, "a.rc-audiochallenge-tdownload-link")))
driver.find_element(By.CSS_SELECTOR, "a.rc-audiochallenge-tdownload-link").click()
非常感谢任何帮助。
答案 0 :(得分:2)
There is no such element locator with a.rc-audiochallenge-tdownload-link
, There is id recaptcha-audio-button
present on audio button... Try Id selector..e.g.
WebDriverWait(driver, 30).until(EC.presence_of_element_located(By.ID, "recaptcha-audio-button"))
driver.find_element(By.CSS_SELECTOR, "recaptcha-audio-button").click()
答案 1 :(得分:0)
答案 2 :(得分:0)
要点击#recaptcha-audio-button
,可以使用(已测试):
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Firefox()
driver.get(url="https://www.google.com/recaptcha/api2/demo")
driver.switch_to.frame(0)
driver.find_element(By.CSS_SELECTOR, "div.recaptcha-checkbox-checkmark").click()
driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element(By.XPATH, "//iframe[@title='recaptcha challenge']"))
driver.find_element(By.ID, "recaptcha-audio-button").click()