2016-04-13 10 views
0

私はセレンのWebドライバを使い慣れていません。作成したテストスクリプトは、以下のgmailにログインするためのスクリプトを書いています。 Iによりデバッグ場合なぜ新しいgmailログインページでselenium web driverを使用してパスワードフィールドを処理できないのですか?

パブリッククラスgmailEmail {

public void login() { 
    ChromeDriver driver=new ChromeDriver(); 
    driver.get("https://www.gmail.com"); 
    driver.findElementById("Email").sendKeys("[email protected]"); 
    driver.findElementByName("signIn").click(); 
    driver.findElementById("Passwd").sendKeys("XXXX"); 
    //driver.findElementByXPath("//*[@id='Passwd']").sendKeys("XXXXX"); 
    driver.findElementByXPath("//*[@id='signIn']").click();  
} 

Iが "driver.findElementById(" いるパスワード ")" でエラーがトリガされ、これを実行し、次のエラーメッセージが

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"Passwd"} 
(Session info: chrome=49.0.2623.112) 
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.10.5 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 40 milliseconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33' 
System info: host: 'Rameshs-MacBook-Pro.local', ip: '192.168.0.105', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/vx/07vnt7mn2jx4fpm983_tq6gm0000gn/T/.org.chromium.Chromium.S1jNgs}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.112, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] 
Session ID: f5790b0589eb054c4e11283c80b82f0e 
*** Element info: {Using=id, value=Passwd} 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) 
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:678) 
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363) 
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413) 
at MobilousLogin.gmailEmail.login(gmailEmail.java:15) 
at MobilousLogin.Registration.main(Registration.java:10) 

を表示しています"driver.findElementById(" Passwd ")"にブレークポイントを挿入すると、スクリプト全体が正常に動作しています。

私がここで間違っていることを理解するのに助けてくれる人がいますか?

+0

また、Gmailのための適切なAPIを使用します。https://developers.google.com/gmail/api/quickstart/java私はこれを試してみましたが、それは絶対に正常に動作している –

答えて

1

にエラーをクロムドライバ機能を追加しますが、セレンがパスワードを入力するようにコマンドを実行した時点で意味の要素を識別することができないと言います要素が読み込まれていないか、UIに表示されません。

ImplicitWaitまたはExplicitWaitsを使用します。

public void login() { 
ChromeDriver driver=new ChromeDriver(); 
driver.get("https://www.gmail.com"); 
driver.findElementById("Email").sendKeys("[email protected]"); 
driver.findElementByName("signIn").click(); 
WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Passwd")).sendKeys(""What ever"); 
    driver.findElementByXPath("//*[@id='signIn']").click();  
} 
+0

おかげで、あなたの助けに感謝。 – user2326333

+0

これで答えを受け入れることができます。 – Paras

0

コードの下で試してみてください。

public void login() { 
    ChromeDriver driver=new ChromeDriver(); 
    driver.get("https://www.gmail.com"); 
    driver.findElementById("Email").sendKeys("[email protected]"); 
    driver.findElementByXPath("//*[@id='signIn']").click(); 
    driver.findElementById("Passwd").sendKeys("XXXX");  
    driver.findElementByXPath("//*[@id='signIn']").click();  
} 

0

は一度試してみてください:あなたは

hereそれらについてあなたが Passwd要素を待つ ExplicitWaitを試すことができますを読むことができます。

WebDriver driver = new ChromeDriver(); 
driver.get("https://www.gmail.com"); 
driver.manage().timeouts().impliciltyWait(30,TimeUnit.SECONDS); 
driver.findElement(By.id("email-display").sendKeys("[email protected]"); 
driver.findElement(By.id("next"").click(); 
driver.findElement(By.id("Passwd")).sendKeys("xxxxxx"); 
    driver.findElementByXPath("//*[@id='signIn']").click();  
関連する問題