简体   繁体   English

如何在C#中使用Selenium请求用户解决验证码?

[英]How to request captcha solving by user using Selenium in C#?

I am coding a application which needs to take a CAPTCHA image, show it to the user and wait for him type it before proceed and submit the form. 我正在编写一个需要拍摄验证码图像的应用程序,将其显示给用户并等待他键入该图像,然后继续提交表单。

I am already able to take the CAPTCHA image but I do not have any idea how to show it to the user and then stop my script until he types it on. 我已经可以拍摄CAPTCHA图像,但是我不知道如何向用户显示该图像,然后停止我的脚本,直到他将其键入为止。

Does anyone could help me? 有人可以帮助我吗?

Cheers. 干杯。

This is really tricky question, but if I had to do it, I would use for 这确实是一个棘手的问题,但是如果我必须这样做,我将用于

a CAPTCHA image, show it to the user 验证码图片,向用户展示

the JavascriptExecutor . JavascriptExecutor It allows you to manipulate the DOM and perform anything you need. 它允许您操纵DOM并执行所需的任何操作。 In this case you can append a container element for the image you already obtained. 在这种情况下,您可以为已经获得的图像附加一个容器元素

As for 至于

any idea how to show it to the user and then stop my script until he types it on 任何想法如何显示给用户,然后停止我的脚本,直到他键入它

I would suggest putting a simple condition, like if the text input contains any alpha-numeric value (easy to check with regex), or whatever value your CAPTCHA validation expects. 我建议您设置一个简单的条件,例如文本输入是否包含任何字母数字值(易于使用正则表达式检查)或验证码验证所期望的任何值。 Until condition is met - you can use Thread.Sleep for certain amount of time eg with 2 sec step between iterations. 在满足条件之前-您可以使用Thread.Sleep一定的时间,例如两次迭代之间要间隔2秒。 Also you can put time limit, avoiding infinite loops. 您还可以设置时间限制,避免无限循环。

Hope this brings some light to your problem. 希望这能给您的问题带来一些启示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM