Home > Enterprise >  Is there any way to bypass Hcaptcha by using selenium python
Is there any way to bypass Hcaptcha by using selenium python

Time:05-16

Is there any way to bypass Hcaptcha by using selenium python, I tried 2captcha(https://2captcha.com/) API, but it doesn't work

CodePudding user response:

While automating Captcha is not the best practice, there are three efficient ways of handling Captcha in Selenium:

  1. By disabling the Captcha in the testing environment
  2. Adding a hook to click the Captcha checkbox
  3. By adding a delay to the Webdriver and manually solve Captcha while testing

CodePudding user response:

bypassing is sadly not an option. What you want to do is to retrieve a solution from sites like 2captcha, while having the solution you need to find the element with the name "h-captcha-response" and edit it so it is visible, after that you need to write the solution of your captcha and submit the form.

driver.execute_script("document.getElementByName('h-recaptcha-response').style = 'width: 250px; height: 40px; border: 1px solid rgb(193, 193, 193); margin: 10px 25px; padding: 0px;';")
    
driver.find_element(By.XPATH,'//*[@id="h-recaptcha-response"]').send_keys(recaptcha_solution)

this is a code I had laying around from another site, but it should make the h-captcha-response show up in your case as well, you need to find the XPATH of the element afterwards and write your own response and click the submit button.

If the code doesn't work try to find the h-recaptcha-response in the HTML and see if it is on the name or the ID of the element, this example assumes it has this name but it is also possible that it is on the ID, in that case you should use

driver.execute_script("document.getElementById('h-recaptcha-response').style = 'width: 250px; height: 40px; border: 1px solid rgb(193, 193, 193); margin: 10px 25px; padding: 0px;';")
  • Related