无法从gmail收件箱中删除邮件

时间:2015-05-20 09:43:40

标签: java testing selenium selenium-webdriver gmail

我需要一个Selenium / java测试点击复选框,该复选框对页面上的所有消息进行高位显示,然后点击删除,我需要测试来重复这些操作。一切都发生在gmail.com。

这是我的代码:

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

这段代码的问题在于,即使for必须完成10次,selenium最多会做4次然后崩溃。

任何提示,伙计们?

编辑:这是我从日食中获得的

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/fxdriver@googlecode.com/components/command-processor.js:9587)

at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/KKUCZ_~1/AppData/Local/Temp/anonymous5326946533230625964webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12257)

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

at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/KKUCZ_~1/AppData/Local/Temp/anonymous5326946533230625964webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:603)

1 个答案:

答案 0 :(得分:0)

我认为,这是因为gmail使用了随意的ID。如果您要执行的操作是从Gmail中删除邮件。我肯定会使用Gmail API。

检查出来:https://developers.google.com/gmail/api/v1/reference/users/messages/delete