Reputation: 15
So I am trying to solve a captcha through selenium. First I try to click the captcha on this website https://patrickhlauke.github.io/recaptcha/. I try xpath and ID method which hasn't had any success. Could someone please help me out here. Here is a picture of what I am trying to click Here is also what I have written. Any help would be appreciated.
from selenium import webdriver
import keyboard
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://patrickhlauke.github.io/recaptcha/")
time.sleep(3)
driver.find_element_by_xpath('//*[@id="recaptcha-anchor"]')
Upvotes: 0
Views: 776
Reputation: 9969
<iframe src="https://www.google.com/recaptcha/api2/anchor?ar=1&k=6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5&co=aHR0cHM6Ly9wYXRyaWNraGxhdWtlLmdpdGh1Yi5pbzo0NDM.&hl=en&v=5mNs27FP3uLBP3KBPib88r1g&size=normal&cb=ufdnmqmcxiqv" width="304" height="78" role="presentation" name="a-y2973t5aots" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox"></iframe>
Your element is in an iframe switch to it. Now your xpath should work.
driver.switch_to.frame(0)
Upvotes: 1