3

私は登録ウェブページを持っていますが、最後のキャプチャは表示されています..

画像からテキストを読み取ることができません。コードと出力について説明します..

@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);
}

出力: エラー

スレッド "main" org.openqa.selenium.NoSuchElementException での例外: 要素が見つかりません: {"method":"xpath","selector":"// [@id='forgotPassword']/table/tbody/tr[ 5]/td[3]/img"} コマンドの実行時間またはタイムアウト: 60.02 秒 このエラーに関するドキュメントについては、 http ://seleniumhq.org/exceptions/no_such_element.html を参照してください。ビルド情報: バージョン: '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' セッション ID: 5f5b2e1a-56a4-49ad-8fd3-2870747a7768 ドライバー情報: org.openqa.selenium.firefox.FirefoxDriver 機能 [{platform=XP, acceptSslCerts =true、javascriptEnabled=true、browserName=firefox、rotatable=false、locationContextEnabled=true、version=23.0.1、cssSelectorsEnabled=true、databaseEnabled=true、handlesAlerts=true、browserConnectionEnabled=true、nativeEvents=true、webStorageEnabled=true、applicationCacheEnabled =true、takesScreenshot=true}] sun.reflect.NativeConstructorAccessorImpl.newInstance0(ネイティブメソッド) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) で sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) で java.lang.reflect.Constructor.newInstance(Constructor.java:513) で org.openqa.selenium.remote.ErrorHandler .createThrowable(ErrorHandler.java:191) org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) org. org.openqa.selenium.By$ByXPath.findElement(By.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']/table/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_(file:///C:/Users/lukup/AppData/Local/Temp/anonymous4043037924964932185webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8880) で不明。 fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/lukup/AppData/Local/Temp/anonymous4043037924964932185webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:396)

4

7 に答える 7

8

以前の回答を詳しく説明すると、CAPTCHA は「Completely Automated Public Turing test to tell Computers and Humans Apart」の頭字語です。したがって、「機械」がそれを解決できる場合、それは実際には仕事ではありません。

それを解決するためにできることがあります - http://www.deathbycaptcha.comのような外部サービスの API を使用することです。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 */
}
于 2013-12-18T14:07:23.273 に答える
1

CAPTCHA の全体的な目的は、UI からの自動化を防ぐことです! アクションを検証するために内部 API を使用することもできます。

于 2013-11-19T07:35:19.253 に答える