2

I am trying to login to Indeed.com using Selenium 4.10.0 using Python 3.10.1. When I do so, I get an hCAPTCHA that I am attempting to solve with the 2captcha API. However, I am unable to find the correct data-sitekey attribute for the website. As a result, I keep getting an ERROR_WRONG_GOOGLEKEY error from the 2captcha API.

To attempt to search for the Indeed sitekey, I used Google Chrome's DevTools. While unable to find an exact data-sitekey attribute, I am able to find a sitekey parameter inside the source of the <iframe> containing the CAPTCHA. Attached are images of my DevTools windows, the <iframe> tag showing where the sitekey is mentioned, and the code I am using to solve the CAPTCHA.

By inspecting the <iframe>, I found a sitekey of 7734ec9b-f8cb-44b2-9fac-3a502cb4f1bf for Indeed. Is this the correct sitekey?

Edit 8/17/2023: From talking to 2Captcha's support, it seems that the sitekey is hidden inside a callback function. Do you have any insight into how to look for the sitekey by inspecting the JavaScript on the page? Thank you.

<iframe src="https://newassets.hcaptcha.com/captcha/v1/c29d40e/static/hcaptcha.html#frame=checkbox&amp;id=0ffwhp2wwjif&amp;host=secure.indeed.com&amp;sentry=true&amp;reportapi=https%3A%2F%2Faccounts.hcaptcha.com&amp;recaptchacompat=true&amp;custom=false&amp;hl=en&amp;tplinks=on&amp;pstissuer=https%3A%2F%2Fpst-issuer.hcaptcha.com&amp;sitekey=7734ec9b-f8cb-44b2-9fac-3a502cb4f1bf&amp;theme=light&amp;origin=https%3A%2F%2Fsecure.indeed.com" 
tabindex="0" 
frameborder="0" 
scrolling="no" 
allow="private-state-token-issuance 'src'; 
private-state-token-redemption 'src'" 
title="Widget containing checkbox for hCaptcha security challenge" 
data-hcaptcha-widget-id="0ffwhp2wwjif" 
data-hcaptcha-response="" 
style="width: 303px; height: 78px; overflow: hidden;">

</iframe>
def solve_captcha(driver, site_key, page_url):
    #We solve the captcha here.
    MY_API_KEY = '<MY_API_KEY>'
    solver = TwoCaptcha(MY_API_KEY)
    response = solver.recaptcha(sitekey=site_key, url=page_url)
    code = response['code']

    #We send the solution here.
    try:
        captcha_element = driver.find_element(By.XPATH, 
                                          "//*[contains(@id,'g-captcha-response')]")
        driver.execute_script(f'arguments[0].value = "{code}";', captcha_element)
        print('Solved CAPTCHA')
    except:
        print('There is no CAPTCHA to solve.')

Image of DevTools window showing sitekey attribute of CAPTCHA on Indeed.com login page.

Howsikan
  • 75
  • 7

2 Answers2

0

I see in your Python code a specific line that indicates it is searching for an element related to Google's reCAPTCHA rather than hCAPTCHA:

captcha_element = driver.find_element(By.XPATH, 
                                      "//*[contains(@id,'g-captcha-response')]")

The g-captcha-response ID is typically associated with Google's reCAPTCHA. Since you are working with hCAPTCHA on Indeed.com, you should be looking for the relevant elements or input fields associated with hCAPTCHA.

To fix this, you should inspect the DOM to find the appropriate element or input field that hCAPTCHA uses to store its response.
And then replace the XPath in the driver.find_element() method with the correct XPath that corresponds to the hCAPTCHA response field.

You need to place the CAPTCHA solution provided by the 2Captcha API into the correct input field to effectively solve the CAPTCHA. If you input it into a reCAPTCHA-specific field, it will not have any effect on the hCAPTCHA challenge, leading to an unresolved CAPTCHA issue.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for this. I'm going to look into whether changing the – Howsikan Aug 18 '23 at 13:59
0

I know that my answer is not the one you are expecting for, but it might be helpful in some cases.

2Catpcha (and other captcha-solving services) has the extension for browsers to solve captchas automatically. You can add the extension to the selenium browser.

After a quick search, it seems that it is not possible to interact with extensions directly from Selenium. One way is to configure the extension manually and then load the configured profile. Another way is to use GUI automation (e.g. pyautogui) tools to perform clicks inside the extension.

elebur
  • 465
  • 1
  • 5
  • Thank you. I think that's what I need to do. Adding this to the browser as an extension saves me programming time. This is a highly useful way of thinking through the problem. – Howsikan Aug 25 '23 at 13:17
  • You're welcome. Glad I could help! – elebur Aug 25 '23 at 18:12