1

I'm trying solve re-captcha in a site using 2captcha service, but always returns to me the error:

Traceback (most recent call last): File "C:\Users\pablo\Desktop\selenium\MercBitk.py", line 48, in GChrome.find_element_by_xpath("//*[@id='g-recaptcha-response']").send_keys(resp.text[3:])

File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys 'value': keys_to_typing(value)})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=77.0.3865.90)

but i'm not finding where am i going wrong ... The code insert the CPF and Password correctly, the code send the captcha and receive the code to 2captcha site correctly too, but can't send it...

The code is:

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import requests
import getpass
import json
from selenium.webdriver.support.ui import Select

from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

GChrome = webdriver.Chrome()
GChrome.get('https://www.mercadobitcoin.com.br/conta/login/')

box_login = GChrome.find_element_by_name('cpfcnpj')
box_login.send_keys('my_cpf')
box_pass = GChrome.find_element_by_name('password')
box_pass.send_keys('my_pass')

box_pass.send_keys(Keys.ENTER)

# 2Captcha service
service_key = 'fa...d4' # 2captcha service key 
google_site_key = '6LfIxCoUAAAAAEEW7DQK_gj3pzzeJz82dTW_SMNH' 
pageurl = 'https://www.mercadobitcoin.com.br/conta/login/' 
url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl 
resp = requests.get(url)

if resp.text[0:2] != 'OK': 
    quit('Service error. Error code:' + resp.text) 
captcha_id = resp.text[3:]

fetch_url = "http://2captcha.com/res.php?key="+ service_key + "&action=get&id=" + captcha_id

for i in range(1, 10):  
    time.sleep(5) # wait 5 sec.
    resp = requests.get(fetch_url)
    if resp.text[0:2] == 'OK':
        break 

GChrome.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')

GChrome.find_element_by_xpath("//*[@id='g-recaptcha-response']").send_keys(resp.text[3:]) #ERROR HERE <<<<<<

Someone can help-me, please? I've been trying for 3 days solve this error

user3602803
  • 99
  • 5
  • 12

3 Answers3

2

I think it's because it's hidden. Try it like this:

driver.execute_script("""
  document.getElementById("g-recaptcha-response").innerHTML = arguments[0]
""", resp.text[3:])

Substitute driver for GChrome in your case.

pguardiario
  • 53,827
  • 19
  • 119
  • 159
  • literally the same error =\ (I tried on google chrome and firefox) – user3602803 Oct 05 '19 at 03:02
  • in the google chrome the error was the same, in firefox it looks like it accepts .send_keys but it's like it doesn't "send", because it goes to the next line of code except the site doesn't exit recaptcha – user3602803 Oct 05 '19 at 03:09
  • the next code is `Wait_reCaptcha = wait.until(ec.visibility_of_element_located((By.XPATH, '//*[@title="Comprar Bitcoins"]')))` and the error is timeout (but from timeout just because it's not coming out of recaptcha, it's like and he would write the answer but not send it) – user3602803 Oct 05 '19 at 03:21
  • 2
    No it wouldn't give the same error. The last one times out because it never becomes visible. – pguardiario Oct 05 '19 at 03:49
  • Sorry, that's right, in Firefox and Chrome are the same error. It's as if selenium writes the code response but doesn't send it – user3602803 Oct 05 '19 at 16:07
1

After the call provided by pguardiario do the following:

driver.execute_script("""
  onSubmit(arguments[0])
""", resp.text[3:])

That's invisible recaptcha that use a callback function and the function name in your case is onSubmit.

2captcha
  • 96
  • 1
  • 3
0

Continuing pguardiario brilliant response and as many of you noticed it fills the textbox but it doesn't send however, due to the circumstance we find ourselves where the textbox is now visible, simply submitting the response should suffice (it did for me):

driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = arguments[0]', resp.text[3:])
driver.find_element_by_id("g-recaptcha-response").submit()
Dharman
  • 30,962
  • 25
  • 85
  • 135
Pedro Kim
  • 1
  • 1