SAT*_*DRA 2 java selenium captcha selenium-webdriver
我有注册网页,但在最后一个验证码显示..
我无法从图像中读取文本.我要提一下代码和输出..
@Test
public void loginTest() throws InterruptedException {
System.out.println("Testing");
driver.get("https://customer.onlinelic.in/ForgotPwd.htm");
WebElement element = driver.findElement(By.xpath("//*[@id='forgotPassword']/table/tbody/tr[5]/td[3]/img"));
System.out.println(" get the instance ");
String elementTest = element.getAttribute("src");
System.out.println("Element : " + elementTest);
}
Run Code Online (Sandbox Code Playgroud)
输出:错误
例外在线程"主" org.openqa.selenium.NoSuchElementException:无法找到元素:{ "方法": "的xpath", "选择器":"// [@ ID = 'forgotPassword'] /表/ tbody的/ TR [ 5]/td [3]/img"}命令持续时间或超时:60.02秒有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本: '2.35.0',修订版: '8df0c6b',时间: '2013年8月12日15时43分19秒' 信息:os.name: 'Windows 7的',os.arch: 'AMD64' ,os.version: '6.1',java.version: '1.6.0_26' 会话ID:5f5b2e1a-56a4-49ad-8fd3-2870747a7768驱动信息:org.openqa.selenium.firefox.FirefoxDriver能力[{平台= XP,acceptSslCerts = TRUE,javascriptEnabled = TRUE,browserName =火狐,旋转=假,locationContextEnabled = TRUE,版本= 23.0.1,cssSelectorsEnabled = TRUE,databaseEnabled = TRUE,handlesAlerts = TRUE,browserConnectionEnabled = TRUE,nativeEvents = TRUE,webStorageEnabled = TRUE,applicationCacheEnabled =真,takesScreenshot =真}]在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)位于org.openqa.selenium.remote.ErrorHandler的java.lang.reflect.Constructor.newInstance(Constructor.java:513)的sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) .orgateThrowable(ErrorHandler.java:191)org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)atg.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)atg. openga.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:404)at org.openqa.selenium.By $ ByXPath.findElement(By.的java:344)在org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)在seleniumtest.CaptchaTest.loginTest(CaptchaTest.java:41)at seleniumtest.CaptchaTest.main(CaptchaTest.java:59)引起:org.openqa.selenium.remote.ErrorHandler $ UnknownServerException:无法找到元素:{"method":"xpath " "选择":" //[@ ID = 'forgotPassword'] /表/ tbody的/ TR [5]/TD [3]/IMG"}生成信息:版本: '2.35.0',修订版: '8df0c6b',时间:"2013-08- 12 15时43分19' 秒信息:os.name: 'Windows 7的',os.arch: 'AMD64',os.version: '6.1',java.version: '1.6.0_26' 驱动程序信息:driver.version :.FirefoxDriver.prototype.findElementInternal_(文件:/// C:/Users/lukup/AppData/Local/Temp/anonymous4043037924964932185webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8880)at. fxdriver.Timer.prototype.setTimeout/<.notify(文件:/// C:/Users/lukup/AppData/Local/Temp/anonymous4043037924964932185webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:396)
只是为了详细解释以前的答案,CAPTCHA作为"完全自动公共图灵测试告诉计算机和人类分开"的首字母缩写.所以,如果"机器"可以解决它,它并不是真正做到的.
为了解决这个问题,您可以做一些事情 - 使用外部服务的API,例如http://www.deathbycaptcha.com.您实现他们的API,将CAPTCHA传递给他们并获得文本.我观察到的平均解算时间约为10-15秒.
实施示例(取自此处)
import com.DeathByCaptcha.AccessDeniedException;
import com.DeathByCaptcha.Captcha;
import com.DeathByCaptcha.Client;
import com.DeathByCaptcha.SocketClient;
import com.DeathByCaptcha.HttpClient;
/* Put your DeathByCaptcha account username and password here.
Use HttpClient for HTTP API. */
Client client = (Client)new SocketClient(username, password);
try {
double balance = client.getBalance();
/* Put your CAPTCHA file name, or file object, or arbitrary input stream,
or an array of bytes, and optional solving timeout (in seconds) here: */
Captcha captcha = client.decode(captchaFileName, timeout);
if (null != captcha) {
/* The CAPTCHA was solved; captcha.id property holds its numeric ID,
and captcha.text holds its text. */
System.out.println("CAPTCHA " + captcha.id + " solved: " + captcha.text);
if (/* check if the CAPTCHA was incorrectly solved */) {
client.report(captcha);
}
}
} catch (AccessDeniedException e) {
/* Access to DBC API denied, check your credentials and/or balance */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
79264 次 |
| 最近记录: |