Reputation: 29
So i'm using this 2captcha API and testing it on a site like omegle.com. The captcha solving happens but the google captcha box doesnt get ticked and nothing happens. Wondering why that is, I know the 2captcha API runs perfectly... but does it only work for HTTP requests and not selenium?
Here is the API link i inserted into the code below: https://github.com/2captcha/2captcha-api-examples/blob/master/ReCaptcha%20v2%20API%20Examples/Python%20Example/2captcha_python_api_example.py
from selenium import webdriver
from time import sleep
from selenium.common.exceptions import InvalidElementStateException
from selenium.common.exceptions import UnexpectedAlertPresentException
import time,os
import requests
fp = webdriver.FirefoxProfile('C:\\Users\\mo\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\b0wnbtro.dev-edition-default')
interest = input("Enter the interests seperate by a comma ")
msg1 = "1"
msg2 ="2"
msg3 = "3"
msg4 = "4"
driver = webdriver.Firefox(fp)
#2CAPTCHA API CODE INSERTED HERE FOR A TEST RUN BEFORE BEING INCORPORATED IN A LOOP
def main():
try:
driver.get('http://www.omegle.com')
time.sleep(1)
#driver.find_elements_by_xpath("//*[contains(text(), 'I'm not a robot')]")
#send.click()
driver.find_element_by_xpath('//textarea[@rows="3"]').clear()
message = driver.find_element_by_xpath('//textarea[@rows="3"]')
time.sleep(3)
message.send_keys(msg1)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(6)
message.send_keys(msg2)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(10)
message.send_keys(msg3)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(25)
message.send_keys(msg4)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
except (InvalidElementStateException, UnexpectedAlertPresentException):
main2()
def main2():
try:
driver.get('http://www.omegle.com')
interest1 = driver.find_element_by_xpath('//input[@class="newtopicinput"]')
interest1.send_keys(interest)
btn = driver.find_element_by_id("textbtn")
btn.click()
time.sleep(5)
driver.find_element_by_xpath('//textarea[@rows="3"]').clear()
message = driver.find_element_by_xpath('//textarea[@rows="3"]')
time.sleep(1)
time.sleep(2)
message.send_keys(msg1)
send = driver.find_element_by_xpath('//button[@class="sendbtn"]')
send.click()
time.sleep(6)
message.send_keys(msg2)
send.click()
time.sleep(10)
message.send_keys(msg3)
send.click()
time.sleep(25)
message.send_keys(msg4)
send.click()
send.click()
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
except (InvalidElementStateException,UnexpectedAlertPresentException) :
disconnect = driver.find_element_by_xpath('//button[@class="disconnectbtn"]')
disconnect.click()
else:
main2()
while True:
try:
main2()
except (InvalidElementStateException,UnexpectedAlertPresentException) :
main()
Upvotes: 1
Views: 6886
Reputation: 96
I hope you already found a solution, but want to leave a comment for those who can get stuck at the same point.
g-recaptcha-response
field. With Selenium you can do that executing JavaScriptdocument.querySelector('#g-recaptcha-response').textContent='token_string'
___grecaptcha_cfg.clients[0].NY.N.callback('token_string')
The path of callback function changes so you need to find a valid one exploring ___grecaptcha_cfg
object.
Upvotes: 6