2016-10-05 1 views
0

セレンを初めて使用しています。私は、アプリケーションを開き、ユーザー名とパスワードを入力してログインするスクリプトを作成しようとしています。私はfirefoxでselenium IDEを使って同じことをやってみました。その働き。しかし、私はセレンとTestNGの(JAVA)私は以下のエラーgetingています使用して、同じしようとすると:TestNGで識別できないフォーム要素

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: /html/body/form[1]/div[2]/table[2]/tbody/tr[4]/td/button (tried for 10 second(s) with 500 MILLISECONDS interval) 
    Build info: version: 'unknown', revision: '3169782', time: '2016-09-29 10:24:50 -0700' 

    Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
    Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:9907/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}] 
    Session ID: a36f7287-5912-48c0-87b2-3d974262c634 
     at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) 
     at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:265) 
     at com.nagest.nrt.NewTest.userLogin(NewTest.java:47) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 

私のページのHTMLスニペットがされています

      <table> 
           <tr> 
            <td>User Id: </td> 
            <td><input type="text" name="USER" id="USER" onfocus="this.style.border='2px solid #3BB9FF';" onblur="this.style.border='2px solid #737373'" /></td> 
           </tr> 
           <tr> 
            <td>Password: </td> 
            <td><input type="password" name="PASSWORD" id="PASSWORD" onfocus="this.style.border='2px solid #3BB9FF';" onblur="this.style.border='2px solid #737373'" /></td> 
           </tr> 
           <tr> 
            <td><input type="hidden" name="TARGET" id="TARGET" value="/epsweb/view/private/search/search.jsf" /></td> 
           </tr> 
           <tr> 
            <td><button name="Logon" type="submit" onfocus="this.style.border='2px solid #3BB9FF';" onblur="this.style.border='2px solid #737373'">Logon</button></td> 
           </tr> 
          </table> 

マイTestNGのJavaコード:

public void userLogin(){ 
     driver.get(baseURL + "login url"); 
     //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
     //driver.findElement(By.id("USER")).sendKeys("aaa"); 
     waitVar.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"USER\"]"))).sendKeys("aaa"); 
     waitVar.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"PASSWORD\"]"))).sendKeys("123");; 
    // driver.findElement(By.name("USER")).sendKeys("aaa"); 
    // driver.findElement(By.name("PASSWORD")).sendKeys("@123"); 
     waitVar.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/form[1]/div[2]/table[2]/tbody/tr[4]/td/button"))).click(); 
     String strPageTitle = driver.getTitle(); 

    } 

多くの組み合わせを使ってみましたが、現在は動作しています。私はfirefox IDEからコードをコピーして、Javaに変換してみました。 XPATHは火かき棒から取得しています。

注:フォーム要素は10秒前に表示されます。

更新:私はSYSOUTラインが印刷getingれる以下のコード

WebElement myelement=driver.findElement(By.id("USER")); 
String tag=myelement.getTagName(); 
     System.out.println("====================="+tag);// ===============input 
     myelement.sendKeys("aaaa"); 

と試みました。しかし、sendKeys()メソッドを使用すると、例外がスローされます。

org.openqa.selenium.WebDriverException: Element is not displayed (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 234 milliseconds 
Driver info: org.openqa.selenium.ie.InternetExplorerDriver 
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:13799/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}] 
Session ID: 1c79492b-0fab-497e-9866-cbba060f6c8a 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) 
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:636) 
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284) 
........... 

この問題はIE11でのみ発生します。私はそれが正しく動作するクロムで試した。

+0

ログインボタンの場合、直接のxpath --- "// button [@ name = 'Logon']"を試して、動作しているかどうかを確認してください...その名前のボタンを1つだけ仮定するか、ページ – Grasshopper

+0

@Grasshopper:コードを更新しました。 Pls now looks –

+0

更新されたコードではどうなっているのですか? – Grasshopper

答えて

0

私は、あなたは待ち時間を増やす必要があると思います。スタックトレースから、待機時間として10秒を使用しているようです。この短い時間内に、ログオンボタンは表示されません。待機時間が長くなると、問題が解決する可能性があります。

+0

@Optimisst_creeper ::コードを更新しました。 Pls look now –

+0

:この問題はIE11でのみ発生しています。私はそれが正しい作品クロムで試した –

0

@Nageswaranm、webdriverを使用して、idまたはnameまたはcssSelectorを使用して要素を検索します。 xpathを使用してwebelementを検索する場合、IEは他のブラウザほど良くはありません。 IEでは遅いです。また、webdriver waitを30秒に増やしてください。これが問題を解決することを願っています。

+0

私もidセレクターを使ってみました。また、同じエラーが発生します。しかし、クロムの同じコードは完全に機能します。 –

関連する問題