java - Selenium Safari 使用 findElement.sendkeys 超时

标签 java eclipse selenium junit selenium-webdriver

我正在尝试使用 Eclipse Luna 在 Safari 上使用 Selenium 测试我的网站。

我的网站使用 Twitter 登录。
当我尝试将 key 发送到 api.twitter.com 上的输入时,出现超时。

请注意,我已经尝试使用 Selenium 的 wiki 页面在 google 上“发送 key ”,甚至在 www.twitter.com 上也运行良好。

我不明白为什么它在 api.twitter.com 上不起作用。
我以为问题出在我的网站上,然后我在另一个也使用 Twitter 身份验证的网站上测试了相同的代码,并且出现了相同的错误。

我什至尝试使用 javascriptExecutor 来填充输入的值,但我也遇到了超时。

有人可以帮我吗?

请在下面找到我的代码和控制台中的跟踪。

package com.fxlabs.wonderboard.nodeTest;
import static org.junit.Assume.assumeTrue;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class BrowserTest {

  private WebDriver driver = null;

  private static boolean isSupportedPlatform() {
    Platform current = Platform.getCurrent();
    return Platform.MAC.is(current) || Platform.WINDOWS.is(current);
  }

  @Before
  public void createDriver() {
    assumeTrue(isSupportedPlatform());
    driver = new SafariDriver();
  }

  @After
  public void quitDriver() {
    driver.quit();
  }

  @Test
  public void shouldBeAbleToPerformAGoogleSearch() {
    driver.get("http://tweetbeam.com");
    new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("TweetBeam Twitter Wall - Visualize Live Tweets"));
    driver.findElement(By.className("navbar-right")).findElement(By.tagName("a")).click();
    new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("Twitter / Autoriser une application"));
    driver.findElement(By.id("username_or_email")).sendKeys("TwitterUsername");
    driver.findElement(By.id("username_or_email")).sendKeys("password");
  }
}

故障追踪:

org.openqa.selenium.TimeoutException: Timed out awaiting response to command "sendKeysToElement" after 30001 ms (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.01 seconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.6.0_65'
Session ID: null
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{platform=MAC, cssSelectorsEnabled=true, javascriptEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=7.1.4}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
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.sendKeys(RemoteWebElement.java:89)
at com.fxlabs.wonderboard.nodeTest.BrowserTest.shouldBeAbleToPerformAGoogleSearch(BrowserTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
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:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
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)

最佳答案

您正在尝试将电子邮件和密码发送到同一字段,不是吗?

driver.FindElement(By.Id("username_or_email")).SendKeys("TwitterUsername");
driver.FindElement(By.Id("password")).SendKeys("password");

这对我来说效果很好。

但是请小心,因为如果页面检测到您已经登录 Twitter,其行为会有所不同。您会看到一个弹出窗口,其中有一些对话框欢迎您。

关于java - Selenium Safari 使用 findElement.sendkeys 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29692239/

相关文章:

java - Gradle 创建损坏的启动脚本。怎么修?

php - 如何使用 php 通过 selenium webdriver 运行 safari?

java - 如何通过 Selenium-Java 连接到 putty 来执行命令集并验证 putty 窗口中的输出

java - 为什么Comparable Interface要用新的Operator来初始化?虽然它是界面?

java - Facebook Java 集成

java - 我可以在eclipse中配置包含java源文件的资源路径吗?

javascript - 是否可以配置 eclipse ee 以在 java 项目中的 js 文件中的 javascript 代码中自动完成?

java - 如何简化 testng XML 文件中的参数传递?

java - 如何使用 GSON 反序列化 PHP 数组

Java - 如何将对象异步保存到数据库?