2015-05-20 96 views
-1

我需要一個Selenium/java測試,點擊複選框,在頁面上顯示所有消息的高位,然後單擊刪除,然後我需要測試重複這些操作。所有發生在gmail.com。從gmail收件箱中刪除郵件失敗

這裏是我的代碼:

for(int s = 0; s <= 10 ; s++) { 
     driver.findElement(By.cssSelector(".T-Jo-auh")).click(); 
     driver.findElement(By.cssSelector(".ar9.T-I-J3.J-J5-Ji")).click(); 
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
} 

和其他版本:

for(int s = 0; s <= 10 ; s++) { 
driver.findElement(By.cssSelector("div.T-Jo-auh")).click(); 
driver.findElement(By.xpath("//div[@id=':5']/div/div/div/div/div/div[2]/div[3]/div/div")).click(); 
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
} 

這段代碼的問題是,硒做最多的事情4次,然後崩潰即使for有許多工作要做10倍。

任何暗示,傢伙?

編輯:這是我從日食

temp 
temporary.temp 
testSzkielet(temporary.temp) 
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with 
Command duration or timeout: 20.17 seconds 
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35' 
System info: host: 'ASUS-HT-2', ip: '10.15.0.127', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_75' 
Session ID: 5a7994fa-a8ac-464a-9223-ffb325cf12fa 
Driver info: org.openqa.selenium.firefox.FirefoxDriver 
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=38.0.1}] 

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:204) 

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) 

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) 

at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268) 

at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79) 

at temporary.temp.testSzkielet(temp.java:48) 

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 

at java.lang.reflect.Method.invoke(Unknown Source) 

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 

at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) 

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 

Caused by: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with 
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35' 
System info: host: 'ASUS-HT-2', ip: '10.15.0.127', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_75' 
Driver info: driver.version: unknown 

at <anonymous class>.fxdriver.preconditions.visible(file:///C:/Users/KKUCZ_~1/AppData/Local/Temp/anonymous5326946533230625964webdriver-profile/extensions/[email protected]/components/command-processor.js:9587) 

at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/KKUCZ_~1/AppData/Local/Temp/anonymous5326946533230625964webdriver-profile/extensions/[email protected]/components/command-processor.js:12257) 

at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/KKUCZ_~1/AppData/Local/Temp/anonymous5326946533230625964webdriver-profile/extensions/[email protected]/components/command-processor.js:12274) 

at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/KKUCZ_~1/AppData/Local/Temp/anonymous5326946533230625964webdriver-profile/extensions/[email protected]/components/command-processor.js:603) 
+2

stacktrace please? –

回答

0

我認爲,這是因爲Gmail使用偶然IDS得到。如果您想要做的是從Gmail中刪除郵件。我一定會使用Gmail API。

查看結果:https://developers.google.com/gmail/api/v1/reference/users/messages/delete

+0

它會工作,當我的測試需要打開每個100顯示的消息,當他們都讀取我需要刪除它們? –

+0

您正在測試Gmail嗎?或者只是試圖自動從Gmail中刪除郵件?如果是這樣,我建議你尋找一個不同的工具。對不起,我試圖瞭解你在做什麼。我的意思是,瞭解上下文 –

+0

我正在測試其他東西,但爲了做到這一點,我需要打開4000封電子郵件,獲取href,在href上做些事情,然後返回到gmail來打開另一條消息。每頁最多可以顯示100條消息,我需要自動刪除100條閱讀消息。爲了打開消息中的鏈接,我使用'getAttribute(「href」)',因爲它在另一個窗口中打開,然後我通過'driver.get(「gmail.com」)'返回,然後它打開另一個消息。消息通過在主題中查找文本來打開。我試圖獲取當前打開的郵件的URL,但不知怎的,它根本不起作用。 –