2015-04-17 30 views
1

我想用Eclipse Luna在Safari上使用Selenium测试我的网站。Selenium Safari使用findElement.sendkeys超时

我的网站使用Twitter登录。
当我尝试将密钥发送到api.twitter.com上的输入时,我有一个超时。

请注意,我已经使用Selenium的wiki页面在Google上尝试了“发送密钥”,即使在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) 
+0

您是否尝试增加您的webdriver等待? –

+0

我已经使用了下面这行,但它仍然不工作 new WebDriverWait(driver,120).until(ExpectedConditions.presenceOfElementLocated(By.id(“username_email”))); – kMomo

+0

仍然收到同样的错误? –

回答

0

你试图发送到同一个领域的电子邮件地址和密码有没有你?

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

这对我很好。

但是要小心,因为如果页面检测到您已经登录到Twitter,页面的行为将有所不同。你会弹出一个对话,欢迎你。

+0

抱歉的错误,但它不是问题,但它是行不通的。即使第一个领域没有填补。 – kMomo