Time out using findElement.sendkeys on Safari
Hello everyone I am trying to test my website with selenium on safari using ECLIPSE LUNA. My website uses Login with twitter. When I try to send key to an input on api.twitter.com I have a timeout. Note that I have already tried "send keys" on google using the wiki page of selenium even on www.twitter.com and It is working fine. I do not understand why it is not working on api.twitter.com. I taught It was my website the problem then I tested the same code on another website also using twitter authentication and I have the same error.
I even tried using javascriptExecutor to fill the value of the input and I also have a time out.
Could anyone help me please? Thanks
Please find below my code and the trace I have in my console. -------------------------CODE------------- 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");
}
}
-----------------------Failure Trace----------- 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)
We had the same issue, but the team managed to fix this by building and installing the Safari Extension manually from scratch.
Not sure why you're testing 10.9 and Java 1.6 ... But I can certainly say this works on El Capitan just fine in the Python Safari Driver which wraps the Java Remote WebDriver
@mketevi I'm facing the same problem. Did you find a fix for this?
The fundamental problem is probably chaining here. You should be using wait for expected conditions. Then with the variable returned call send keys.
@uchuugaka
driver.navigate.to "https://github.com/login"
element = driver.find_element(:id, "login_field")
element.send_keys("nidhimj22");
Waiting and sending also didn't help.
I'm having exact same problem with twitter
But looks like there is an open issue for this already https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6537
this issue occurs when safari is trying to access sites with CSPs (Content Security Policy)(http://www.html5rocks.com/en/tutorials/security/content-security-policy/). Most CSPs don't allow inline script injection, which is what the SafariDriverExtension is trying to doing (https://github.com/SeleniumHQ/selenium/wiki/SafariDriver-Internals#Global_Extension.md) Github and Twitter are examples of where CSPs are in place. To test, make sure you have your SafariDriverExtension enabled and goto either site and inspect any element and click the "red stop sign" -- it will indicate, "Refused to load the script . . . . . . because it violates the following Content Security Policy directive: . . . . . " . Now repeat the process with the SafariDriverExtension disabled and notice no errors. And with that, I don't believe Safari will be able to drive sites with CSPs with its current architecture.
With the release of Safari 10, Apple now offers official support WebDriver. Because of this, the Selenium project no supports the legacy implementation from 2.x.
Users are advised to switch to Apple's driver and file bugs at https://bugreport.apple.com/
We are no longer tracking issues for Selenium's SafariDriver and thus closing this issue.