Jump to content

Captcha's failing through Selenium


Zummy

Recommended Posts

2 minutes ago, Zummy said:

Hey guys, I use Selenium to recover and create accounts but I have a lot of fails where the captcha is solved but upon continuing to the next page, the page just refreshes.

Does anyone know what happens here or has any experience in completing this process by the same means? Thanks!

1) Make sure your proxies aren't blocking the recaptcha from loading (Inspect and look at errors)

2) Use this to inject the captcha response:

JavascriptExecutor js = (JavascriptExecutor) driver;
					js.executeScript("document.getElementById(\"g-recaptcha-response\").innerHTML=\""+response+"\";");

3) make sure you're submitting the form and not clicking it

if(isElementPresent(driver, By.id("password-recovery-form"))){
				driver.findElement(By.id("password-recovery-form")).submit();
			}

 

Link to comment
Share on other sites

8 minutes ago, Naked said:

1) Make sure your proxies aren't blocking the recaptcha from loading (Inspect and look at errors)

2) Use this to inject the captcha response:

3) make sure you're submitting the form and not clicking it

Thanks for the reply!

I'm using the same technique:

RemoteWebDriver r = (RemoteWebDriver) driver;
String setResponseToken = "document.getElementById('g-recaptcha-response').innerHTML='" + CAPTCHA + "'";
r.executeScript(setResponseToken);
r.executeScript("onSubmit()");

What anti captcha service do you use?

Link to comment
Share on other sites

1 minute ago, Zummy said:

Thanks for the reply!

I'm using the same technique:


RemoteWebDriver r = (RemoteWebDriver) driver;
String setResponseToken = "document.getElementById('g-recaptcha-response').innerHTML='" + CAPTCHA + "'";
r.executeScript(setResponseToken);
r.executeScript("onSubmit()");

What anti captcha service do you use?

anticaptcha

Did you verify the captcha is loading?

Link to comment
Share on other sites

1 minute ago, Naked said:

anticaptcha

Did you verify the captcha is loading?

I'm also using anticaptcha, what's your fail-rate?

No I don't verify if it has been loaded, can I check for certain HTML elements to verify if it's loaded?

I don't think it's proxy related, sometimes it does and sometimes it doesn't complete the captcha with the same proxy.

Link to comment
Share on other sites

14 minutes ago, Zummy said:

I'm also using anticaptcha, what's your fail-rate?

No I don't verify if it has been loaded, can I check for certain HTML elements to verify if it's loaded?

I don't think it's proxy related, sometimes it does and sometimes it doesn't complete the captcha with the same proxy.

Failure rate is low (not sure on actual number).

Should always check if it's loaded. You can do this by looking for the element.

Google captcha likes to misbehave when using a SOCKS connection :)

Link to comment
Share on other sites

# Login form handler runescape.com
def runescape_login(driver, username, password):
    # On runescape account login screen
    print("On the login page")
    username_field = driver.find_element_by_id("login-username")
    password_field = driver.find_element_by_id("login-password")

    print("Placing log in credentials")

    if username not in username_field.text:
        username_field.clear()
        print("Filling username data")
        username_field.send_keys(username)

    print("Filling password data")
    password_field.send_keys(password)

    if runescape_site_key in driver.page_source:
        # Generates the captcha token and executes javascript
        print("RecaptchaV2")

        captcha_id = get_captcha_id(runescape_login_url, runescape_site_key)
        captcha_token = get_captcha_token(captcha_id)
        driver.execute_script("document.getElementById('g-recaptcha-response').innerHTML = '"
                              + captcha_token + "'; onSubmit();")
        time.sleep(3)
        pass
    else:
        print("Clicking the login button")
        driver.find_element_by_id("du-login-submit").click()

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, Zummy said:

Hey guys, I use Selenium to recover and create accounts but I have a lot of fails where the captcha is solved but upon continuing to the next page, the page just refreshes.

Does anyone know what happens here or has any experience in completing this process by the same means? Thanks!

Also just a side note, I’d recommend ditching selenium and running the script over post/get requests instead as it will be far more lightweight.

Link to comment
Share on other sites

Thanks for all the replies guys! If I understand this correctly, as long as the sitekey is present in the page source, recaptcha is loaded?

9 hours ago, Impensus said:

Also just a side note, I’d recommend ditching selenium and running the script over post/get requests instead as it will be far more lightweight.

I did that in the beginning until they changed to invisible captcha's. I don't know much about HTTP requests and calling functions while doing so (onSubmit()), so I changed it all to Selenium.

Link to comment
Share on other sites

7 hours ago, Zummy said:

Thanks for all the replies guys! If I understand this correctly, as long as the sitekey is present in the page source, recaptcha is loaded?

I did that in the beginning until they changed to invisible captcha's. I don't know much about HTTP requests and calling functions while doing so (onSubmit()), so I changed it all to Selenium.

Basically how 2captcha works(not sure if anti captcha is the same) is that you send a request for a url with their site key. 2captcha use this to generate a captcha on their end and send you the ID of this captcha. You send a request for it to be solved and given the token back. To answer your question, every site that has recaptcha must have a site key and this must be present somewhere in the source.

and I’d say it’s worth giving http requests a look. I had no clue about them either until I tried it and a bit of trial and error got it working.

Link to comment
Share on other sites

On 4/3/2019 at 11:34 PM, Chris said:

# Login form handler runescape.com
def runescape_login(driver, username, password):
    # On runescape account login screen
    print("On the login page")
    username_field = driver.find_element_by_id("login-username")
    password_field = driver.find_element_by_id("login-password")

    print("Placing log in credentials")

    if username not in username_field.text:
        username_field.clear()
        print("Filling username data")
        username_field.send_keys(username)

    print("Filling password data")
    password_field.send_keys(password)

    if runescape_site_key in driver.page_source:
        # Generates the captcha token and executes javascript
        print("RecaptchaV2")

        captcha_id = get_captcha_id(runescape_login_url, runescape_site_key)
        captcha_token = get_captcha_token(captcha_id)
        driver.execute_script("document.getElementById('g-recaptcha-response').innerHTML = '"
                              + captcha_token + "'; onSubmit();")
        time.sleep(3)
        pass
    else:
        print("Clicking the login button")
        driver.find_element_by_id("du-login-submit").click()

 

Thank you so much! Was trying to get mine to work for the past few days, I realized my mistake was with the javascript, I didn't add onSubmit(); after I I fill everything else in!

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...