recaptcha java,如何使用Selenium和Java单击reCaptcha

Why am I getting errors when trying to get the driver to click on the reCaptcha button?

this is the site where i am trying to get it to work: https://rsps100.com/vote/760/

This is my current code so far:

WebElement iframeSwitch = driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div/div/div[2]/div/form/div/div/div/div/iframe"));

driver.switchTo().frame(iframeSwitch);

driver.findElement(By.cssSelector("div[class=recaptcha-checkbox-checkmark]")).click();

解决方案

To invoke click() on the reCaptcha checkbox as the element is within an you need to:

Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.

Induce WebDriverWait for the desired elementToBeClickable.

You can use the following solution:

Code Block:

public class ReCaptcha_click {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");

ChromeOptions options = new ChromeOptions();

options.addArguments("start-maximized");

options.addArguments("disable-infobars");

options.addArguments("--disable-extensions");

WebDriver driver = new ChromeDriver(options);

driver.get("https://rsps100.com/vote/760");

new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name, 'a-') and starts-with(@src, 'https://www.google.com/recaptcha')]")));

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.recaptcha-checkbox-checkmark"))).click();

}

}

Browser Snapshot:

f7c1798837d6bd9a21735f2497bd7da6.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值