When using driver.get on a certain website (driver.get("http://steamcommunity.com/market/search?appid=730")), I get this error:
Exception in thread "main" org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking fireEvent
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'daltonpc', ip: '10.0.0.2', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:504)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:480)
at org.openqa.selenium.example.FinderClass.findOtherWeapon(FinderClass.java:60)
at org.openqa.selenium.example.Main.main(Main.java:20)
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking fireEvent
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:824)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:748)
at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:920)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:925)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1298)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:290)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:475)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:491)
... 3 more
Caused by: java.lang.RuntimeException: Exception invoking fireEvent
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:148)
at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:448)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:630)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
... 22 more
Caused by: com.gargoylesoftware.htmlunit.ScriptException: illegal radix 0. (http://steamcommunity-a.akamaihd.net/public/shared/javascript/shared_global.js?v=BESEFoKTgss6&l=english#1358)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:814)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:748)
at com.gargoylesoftware.htmlunit.javascript.host.EventNode.fireEvent(EventNode.java:396)
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 net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:120)
... 32 more
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: illegal radix 0. (http://steamcommunity-a.akamaihd.net/public/shared/javascript/shared_global.js?v=BESEFoKTgss6&l=english#1358)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.runtimeError(StrictErrorReporter.java:81)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1047)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1094)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError1(Context.java:1062)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.numberToString(ScriptRuntime.java:813)
at net.sourceforge.htmlunit.corejs.javascript.NativeNumber.execIdCall(NativeNumber.java:129)
at net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject.call(IdFunctionObject.java:89)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:630)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
... 47 more
It works fine with other urls, and it also worked with this one until I enabled javascript by putting true in WebDriver driver = new HtmlUnitDriver(true);. I needed to do this because my program wasn't working properly without javascript, and it seems like this steam community market page requires javascript in order to access it, even by just typing in the url. What am I doing wrong?
Using a user agent will solve the ScriptException. Use DesiredCapabilties to do so. See below code:
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setBrowserName("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20160101 Firefox/66.0");
HtmlUnitDriver driver = new HtmlUnitDriver(capabilities);
driver.setJavascriptEnabled(true);
driver.get("http://steamcommunity.com/market/search?appid=730");
System.out.println(driver.getPageSource());
This works fine.
Although, an alternate solution would be to use PhantomJSDriver which I found to be much better at locating elements.
Download PhantomJS.exe file and set the exe's file path as PHANTOMJS_EXECUTABLE_PATH_PROPERTY
public class CopyOfTest1
{
PhantomJSDriver driver;
WebDriverWait wait;
DesiredCapabilities capabilities;
CopyOfTest1()
{
//set binary path of phantomJS driver
capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "drivers/phantomjs.exe");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX,"Y");
capabilities.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
//intialize driver and set capabilties
driver = new PhantomJSDriver(capabilities);
//intitlaize webdriverwait class
wait = new WebDriverWait(driver, 30);
}
void start()
{
driver.get("http://steamcommunity.com/market/search?appid=730");
System.out.println(driver.getPageSource());
driver.quit();
}
public static void main(String[] args) throws Exception
{
new CopyOfTest1().start();
}
}
You are missing double quotation " in url. Try the following
driver.get("http://steamcommunity.com/market/search?appid=730")
Related
I am implementing selenium grid and the capability to launch the tests using the RemoteWebDriver. I am using docker standalone image.
Below is my code
public void setUp() throws MalformedURLException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox");
options.addArguments("--headless");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"),options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
driver.get("www.google.com");
driver.manage().window().maximize();
}
Command:
docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:latest
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f810511cbe2 selenium/standalone-chrome:latest "/opt/bin/entry_poin…" 9 seconds ago Up 7 seconds 0.0.0.0:4444-\>4444/tcp, 0.0.0.0:7900-\>7900/tcp, 5900/tcp modest_keller
I have also added selenium-java, selenium-manager and testing dependencies in pom.xml. I am using:
Java 11
Selenium 4.8.0
Selenium Manager 4.8.0
Chrome version 109.0.5414.119
IDE IntelliJ
MacOS
I am getting below errors:
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response: var json = Object.freeze('{"consoleLink": "\\u002fgrid\\u002fconsole","type": "Grid Hub","class": "org.openqa.grid.web.servlet.DisplayHelpHandler$DisplayHelpServletConfig","version": "3.141.59"}');
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:134)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:139)
at baseTest.BaseTest.setUp(BaseTest.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:180)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:829)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
at org.testng.SuiteRunner.run(SuiteRunner.java:330)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
at org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng.TestNG.run(TestNG.java:1067)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: org.openqa.selenium.json.JsonException: Unable to parse: \<!DOCTYPE html\>
at org.openqa.selenium.json.Json.toType(Json.java:57)
at org.openqa.selenium.json.Json.toType(Json.java:50)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:131)
... 34 more
Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: <. Last 1 characters read: <
Build info: version: '4.8.0', revision: '267030adea'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '13.1', java.version: '11.0.17'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:126)
at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$6(JsonTypeCoercer.java:141)
at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:127)
at org.openqa.selenium.json.Json.toType(Json.java:71)
at org.openqa.selenium.json.Json.toType(Json.java:55)
... 36 more
Add /wd/hub at the end of the your driver URL as:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
or
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), options);
This question already has answers here:
WebDriverException: Error forwarding the new session Error forwarding the request Connect to my_ip:5555 [/my_ip] failed: Connection timed out
(3 answers)
System.InvalidOperationException : Error forwarding the new session cannot find : Capabilities {browserName: chrome, marionette: false}
(2 answers)
Closed 2 years ago.
I am trying to run a Selenium Java testing using grid. My hub is in an aws windows instance and node is my local computer. I am able to connect my local system to aws instance VM using port forwarding on a wifi connection. But on running Java scripts getting below error
HUB command Used:
java -jar selenium-server-standalone-3.14.0.jar -role hub -port 80
Node connecting command:
java -Dwebdriver.chrome.driver="chromedriver.exe" -jar selenium-server-standalone-3.14.0.jar -role node -hub http://3.21.32.100:80/grid/register -remoteHost http://asagta-62417.portmap.io:62417 -port 4596
TestNg Test
public class TestClass
{
WebDriver driver;
String baseURL, nodeURL;
#BeforeTest
public void setUp() throws MalformedURLException {
System.setProperty("webdriver.chrome.driver", "jars/chromedriver.exe");
baseURL = "http://demo.guru99.com/test/guru99home/";
nodeURL = "http://3.21.32.100:80/wd/hub";
ChromeOptions options = new ChromeOptions();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
driver = new RemoteWebDriver(nodeURL,capabilities);
}
#AfterTest
public void afterTest() {
driver.quit();
}
#Test
public void sampleTest() {
driver.get(baseURL);
if (driver.getPageSource().contains("MOBILE TESTING")) {
Assert.assertTrue(true, "Mobile Testing Link Found");
}
else {
Assert.assertTrue(false, "Failed: Link not found");
}
}
}
Stacktrace:
org.openqa.selenium.WebDriverException: Error forwarding the new session new session request for webdriver should contain a location header or an 'application/json;charset=UTF-8' response body with the session ID.
Command duration or timeout: 46.30 seconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z'
System info: host: 'EC2AMAZ-BPUIVPF', ip: '172.31.43.132', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_261'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:122)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:143)
at batool.TestClass.setUp(TestClass.java:23)
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session new session request for webdriver should contain a location header or an 'application/json;charset=UTF-8' response body with the session ID.
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:118)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:85)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:860)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.seleniumhq.jetty9.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.Server.handle(Server.java:530)
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:347)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:256)
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:102)
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
at java.lang.Thread.run(Unknown Source)
OS:Windows 10
Execution Environment : JavaSE-1.8 (jre1.8.0_144)
JARs and class folders on build path:
client-combined-3.6.0-sources.jar
client-combined3.6.0.jar
selenium-server-standalone-3.6.0.jar
Browser:
FireFox 56.0
Code Snippet:
System.setProperty("webdriver.firefox.marionette","C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");
WebDriver driver = new FirefoxDriver ();
driver.get("https://www.facebook.com");
Error:
Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:112)
at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:97)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:140)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at FacebookFriends.main(FacebookFriends.java:18)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:45149/hub/status] to be available after 45005 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:110)
... 8 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 9 more
First of all You are using a little bit old version of gecko driver. The newest from: https://github.com/mozilla/geckodriver/releases
Then You need to set up system property with:
File gecko = new File("C:/Users/admin/Downloads/geckodriver-v0.19.0-win32/geckodriver.exe");
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
If You really want to use marionette check answers on: Difference between webdriver.firefox.marionette & webdriver.gecko.driver
I haved this error for 2 days, the solution for me was in Set.Plataform put Platafor.ANY or Plataform.Windows because Plataform.WIN10 not worked, marionette wasn't necessary and I added and neether works, only works this. I hope this helps someone else:
public class Main {
public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities().firefox();
desiredCapabilities.setPlatform(Platform.ANY);
desiredCapabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"), desiredCapabilities);
driver.navigate().to("http://www.google.com");
driver.findElementByName("q").sendKeys("execute automation");
driver.findElementByName("q").sendKeys(Keys.ENTER);
driver.close();
// write your code here
}
}
You can also try using double \\ in the path of the geckodriver.
Also instead of using :
System.setProperty(
"webdriver.firefox.marionette",
"C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");
Can you try using
System.setProperty(
"webdriver.gecko.driver",
"C:\\Users\\admin\\Downloads\\geckodriver-v0.11.1-win32\\geckodriver.exe");
Title : Problem Resolved
Solution Accepted :
- Use latest version of gecko driver
Code Used
- System.setProperty("webdriver.gecko.driver","C:\Marionette\geckodriver_1.exe" );
I have the following method:
private void checkIfLoggedIn() {
try{
try {
new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("a[href*='score']")));
}
catch (WebDriverException e) {
}
loggedInState = 2;
}
catch (TimeoutException e) {
loggedInState = -1;
}
}
Simply put, this method's job is to wait until the webpage finishes loading the logged-in pa
ge, and let the rest of the code know by changing a variable. This code works perfectly the vast majority of the time, however if the driver is closed (by another thread) before it finishes, it crashes. I'm perfectly fine with the code stopping - If the webpage has closed it has most likely finished it's task (or crashed for a different reason). The problem is that the error log (posted below) won't go away. I'v even tried something as broad as catch (Exception e)in order to catch any possible exception, but the crashlog won't go away. Any Advice would be appreciated!
EDIT: Thanks to #jdigital, I discovered that the code was in fact catching the exceptions, however that was masked by Selenium outputting it's own exceptions. Any advice on how to have selenium stop outputting errors would be appreciated!
Jan 27, 2014 6:48:29 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.selector: a[href*='score'])
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: '[Edited out for Privacy]', ip: '[Edited out for Privacy]', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:396)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:432)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:730)
at org.openqa.selenium.support.ui.ExpectedConditions.access$0(ExpectedConditions.java:728)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:130)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at Web.WebCrawler.checkIfLoggedIn(WebCrawler.java:89)
at Web.WebCrawler.access$0(WebCrawler.java:86)
at Web.WebCrawler$1.run(WebCrawler.java:80)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:178)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:319)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:298)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:366)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 13 more
You should be able to set Selenium's Logging Preferences to customize the exception output.
EDIT:
Perhaps the instructions at the above referenced link aren't too helpful.
It looks like Selenium uses the standard Java logger interface. Get hold of the RemoteWebDriver object and then turn off its logging via setLogLevel(java.util.logging.Level.OFF).
For another alternative, the FirefoxDriver allows stdout/stderr to be redirected to a file. This has the advantage of allowing you to inspect the output should you need to do so; otherwise, you can just overwrite it or delete it.
I'm using JUnit, Selenium WebDriver and try to make some tests with HtmlUnit and http://vk.com site but fail.
It looks like FirefoxDriver works great for me.
Here is code:
#Before
public void setUp() {
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
capabilities.setVersion("24.0");
capabilities.setJavascriptEnabled(true);
driver = new HtmlUnitDriver(capabilities);
driver.manage().timeouts()
.implicitlyWait(Integer.parseInt(TIMEOUT), TimeUnit.SECONDS);
driver.get("http://vk.com");
}
#Test
public void SomeTest() {
/* LoginPage - described class in PageObject traditions */
LoginPage start = new LoginPage(driver);
LOG.info(driver.getPageSource());
//...
}
When I start it I get the an exception:
org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setInnerHTML
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'hera', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10-3-amd64', java.version: '1.6.0_27'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:484)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:463)
at vk.Execution.setUp(Execution.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Any suggestions?
ps. This is black-box testing I've no access to change internal code on site.
Different drivers have different ways to handle javascript.
Htmlunit uses Rhino and firefox-driver uses Firefox's default javascript handler and hence, you see different results with different drivers.
Replace htmlUnit() with firefox() for your fix.
DesiredCapabilities capabilities = DesiredCapabilities.firefox()
capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
capabilities.setVersion("24.0");
driver = new HtmlUnitDriver(capabilities);