Home:ALL Converter>Python + Selenium + 2Captcha

Python + Selenium + 2Captcha

Ask Time:2019-10-05T03:24:55         Author:user3602803

Json Formatter

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

Author:user3602803,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58242160/python-selenium-2captcha
2captcha :

After the call provided by pguardiario do the following:\n\ndriver.execute_script(\"\"\"\n onSubmit(arguments[0])\n\"\"\", resp.text[3:])\n\n\nThat's invisible recaptcha that use a callback function and the function name in your case is onSubmit.",
2019-10-05T16:22:36
pguardiario :

I think it's because it's hidden. Try it like this:\n\ndriver.execute_script(\"\"\"\n document.getElementById(\"g-recaptcha-response\").innerHTML = arguments[0]\n\"\"\", resp.text[3:])\n\n\nSubstitute driver for GChrome in your case.",
2019-10-05T00:57:58
yy