Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

selenium / chronium can't solve recaptchas

When selenium (chrome with chromedriver) window is opened I can't login in a form. Even after I manually solve the captcha (I have to do a million tests), it says it's solved. I press login and bam it resets.

Outside of the selenium window it does work. Any idea how to solve this?

question from:https://stackoverflow.com/questions/65840236/selenium-chronium-cant-solve-recaptchas

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all, Selenium can not solve the captchas. Also about the second part of your problem (After you log in, it resets.) I think it could be the time issue. You need to make your execution wait until you solve the captcha manually.

For example, a captcha should have one checkbox, and after you solved the captcha it should automatically be checked. You can make your execution wait until that checkbox is checked.

You can use something like this:

    WebDriverManager.chromedriver().setup();

    WebDriver driver = new ChromeDriver();

    WebElement captchaCheckBox = driver.findElement(By.xpath("the xpath location of the checkbox from captcha")); //You can use other locators too, like id or name or whatever.

    WebDriverWait wait = new WebDriverWait(driver,20);

    wait.until(ExpectedConditions.elementToBeSelected(captchaCheckBox));

After you do that you can continue to do your other actions like clicking the log in button, navigating to the main page of your application, etc.

Also if the code above doesn't work, after you find the checkbox you can try to find the attribute of that webelement which shows whether the checkbox is checked or not. It can be something like this inside the HTML tag: aria-checked="false"

After you find that attribute in the tag of your webelement you can use this code:

    wait.until(ExpectedConditions.attributeContains(captchaChecBox, aria-checked, "true"));

instead of this:

    wait.until(ExpectedConditions.elementToBeSelected(captchaCheckBox));

If I understood the problem correctly, this should work. I hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...