google captcha java,Java Selenium + 2Captcha +提交表单

Hello i am trying to automate some process here . i am using 2captch to solve captcha , please check out image .

I have got site_key and api_key , now i am sending api_key + site_key and it is returning me response_token, i have added returned response token into g-recaptcha-response but it is not submitting form.

what i want is that : i can solve captcha and submit form .

Here is my current java code :

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

ChromeDriver driver;

driver = new ChromeDriver();

driver.manage().deleteAllCookies();

driver.manage().window().maximize();

driver.get("https://id.sonyentertainmentnetwork.com/signin/?client_id=fe1fdbfa-f1a1-47ac-b793-e648fba25e86&redirect_uri=https://secure.eu.playstation.com/psnauth/PSNOAUTHResponse/pdc/&service_entity=urn:service-entity:psn&response_type=code&scope=psn:s2s&ui=pr&service_logo=ps&request_locale=en_GB&error=login_required&error_code=4165&error_description=User+is+not+authenticated&no_captcha=false#/signin?entry=%2Fsignin");

Thread.sleep(5000);

driver.findElement(By.xpath("//input[@title='Sign-In ID (Email Address)']")).sendKeys("email");

Thread.sleep(2000);

driver.findElement(By.xpath("//input[@title='Password']")).sendKeys("password");

Thread.sleep(2000);

driver.findElement(By.xpath("//button[@class='primary-button row-button text-button touch-feedback']")).click();

Thread.sleep(3000);

By captcha = By.xpath("//iframe[@title='recaptcha challenge']");

String src = driver.findElement(captcha).getAttribute("src");

String key = getKey(src);

System.out.println(key);

String apiKey = "API_KEY";

String googleKey = key;

String pageUrl = "https://id.sonyentertainmentnetwork.com/signin/?client_id=fe1fdbfa-f1a1-47ac-b793-e648fba25e86&redirect_uri=https://secure.eu.playstation.com/psnauth/PSNOAUTHResponse/pdc/&service_entity=urn:service-entity:psn&response_type=code&scope=psn:s2s&ui=pr&service_logo=ps&request_locale=en_GB&error=login_required&error_code=4165&error_description=User+is+not+authenticated&no_captcha=false#/signin?entry=%2Fsignin";

String proxyIp = "183.38.231.131";

String proxyPort = "8888";

String proxyUser = "username";

String proxyPw = "password";

TwoCaptchaService service = new TwoCaptchaService(apiKey, googleKey, pageUrl, proxyIp, proxyPort, proxyUser, proxyPw, ProxyType.HTTP);

try {

String responseToken = service.solveCaptcha();

System.out.println("The response token is: " + responseToken);

JavascriptExecutor js = (JavascriptExecutor) driver;

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

} catch (InterruptedException e) {

System.out.println("ERROR case 1");

e.printStackTrace();

} catch (IOException e) {

System.out.println("ERROR case 2");

e.printStackTrace();

}

UPDATED CODE :

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

Thread.sleep(500);

WebElement frameElement = driver.findElement(captcha);

driver.switchTo().frame(frameElement);

js.executeScript("document.getElementById('recaptcha-verify-button').click();");

it is clicking on button but , it shows Please select all matching images.

. please check out screenshot

解决方案

All you need to do is submit it like this:

js.executeScript("document.getElementById('g-recaptcha-response').innerHTML='" + responseToken + "';");

Thread.sleep(500);

js.executeScript("document.getElementById('captcha-form').submit();");

also don't forget to check this ID : "captcha-form", it can be different

To reach to element "recaptcha-verify-button":

After you got the response from the API;

By frame = By.xpath("//iframe[@title='recaptcha challenge']");

WebElement frameElement = driver.findElement(frame);

driver.switchTo.frame(frameElement);

then you can execute your script. Finally, for your script if your captcha form is a button

you

cannot call submit();

you

can call click();

Final Answer:

Also check this: js.executeScript("widgetVerified('TOKEN');");

To find the function called widgetVerified() please run this code in the console.

___grecaptcha_cfg.clients[0]

this will return a json, inside of that json try to find the callback function in @Awais case it was wigdetVerified(e)

Warn : Don't use any adblocker

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值