I'm using Selenium to automate a process and I am using ChroPath to find Elements like XPath for easier use. But sometimes the elements are not available; example:
Element that I'm trying to locate
try:
P_Captcha_ButtonWait = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH("//div[@class='antigate_solver recaptcha in_process']"))))
print("Captcha is being solved. Waiting 40 seconds...")
time.sleep(40)
CaptchaSolved = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[@class='antigate_solver recaptcha solved']")))
time.sleep(3)
print("It's rocking!!!!")
driver.find_element_by_xpath(
"/html[1]/body[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/p[3]/button[1]").click()
except:
P_Email_Verification = WebDriverWait(driver, 10).until(EC.presence_of_element_located((
By.XPATH, "/html[1]/body[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[2]/label[1]/div[1]/input[1]")))
driver.find_element_by_xpath(
"/html[1]/body[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[2]/label[1]/div[1]/input[1]").click()
print("Something went wrong and idk why?")
This is the line of Code I have written for the Captcha part and I am actually using Anti-Captcha.com Extension and I want to locate the text that Anti-Captcha gives when it is solving the captcha. It looks like this: Anti-Captcha
Also, the website I'm trying this on is ProtonMail, the page where you verify your self if you're a human or not.
I have already coded the part where you verify your self using E-Mail, but I want Captcha as a main-use and the E-Mail Verification as a backhand in case things go wrong with Captcha.
I have tried researching for locating the element, but the only thing I could find is with an image searcher? I have been forced to use PyAutoGui with absolute directions most of the time for some elements like Button clicking or Clicking in certain fields with absolute direction because I couldn't properly find the XPath.
I'd like to know some ways experience users locate elements.
Update:
This is another attempt of me trying to fix the code and trying different methods but still not working.
try:
P_Captcha_ButtonWait = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//a[@class='status'][contains(.,'Solving is in process...')]")))
if P_Captcha_ButtonWait is True:
print("Captcha is being solved. Waiting 40 seconds...")
time.sleep(40)
CaptchaSolved = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[@class='antigate_solver recaptcha solved'][contains(.,'Solved')]")))
if CaptchaSolved is True:
time.sleep(3)
print("It's rocking!!!!")
driver.find_element_by_xpath(
"/html[1]/body[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/p[3]/button[1]").click()
except TimeoutException:
# P_Email_Verification = WebDriverWait(driver, 10).until(EC.presence_of_element_located((
# By.XPATH, "/html[1]/body[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[2]/label[1]/div[1]/input[1]")))
# driver.find_element_by_xpath(
# "/html[1]/body[1]/div[2]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[2]/label[1]/div[1]/input[1]").click()
print("Something went wrong and idk why?")
driver.close()
I have made the lines in except
as comments for now as my main goal is to fix finding the Anti-Captcha Element.
Basically whatever I do, try
won't run because the Element isn't founded.
I thought to make it work in another way; if Captcha option is available on selection, driver can wait 30-80 seconds until Captcha is solved. (that's how long anti-captcha takes approx most of the times to solve a captcha). But sometimes they take up to 200 seconds so that will run into errors and 'cause the whole script failing. So that's the reason why I want to locate this element, because it's easier and keeps the script running.