Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro selenium: Could not start a new session. Possible causes are invalid address.....

Boa tarde.

Estou tendo esse erro desde a primeira tentativa de realizar o código da primeira aula. já atualizei os drives(Tanto do Firefox como do Chrome), estou utilizando a versão mais recente do Selenium e nada funciona.

Código:

WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com.br/");
        WebElement q = driver.findElement(By.name("q"));
        q.sendKeys("Caelum");
        q.submit();

erro:

mai 15, 2018 1:23:36 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFORMAÇÕES: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'DESKTOP-L7F0R37', ip: '192.168.0.22', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:117)
    at TesteAutomatizado.main(TesteAutomatizado.java:13)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:4444
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:240)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:158)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:104)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:54)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    ... 4 more
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 okhttp3.internal.platform.Platform.connectSocket(Platform.java:125)
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:238)
    ... 27 more

estou pesquisando mas até agora não achei solução.

obrigado.

3 respostas

Oi Gabriel, não sou um super especialista em selenium, mas dando uma olhada na internet parece que o problema pode ter a ver com alguma instalação em um local customizado do firefox ou chrome. https://github.com/SeleniumHQ/selenium/issues/2672

Talvez você tenha que usar o System.setProperty e definir o caminho na mão.

Alberto já fiz isso diversas vezes o erro continua.

Mas percebi um comportamento, se eu executo o drive ou do Firefox ou do Chrome, e executo o código o erro muda.

erro:

mai 15, 2018 6:03:11 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFORMAÇÕES: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: POST /wd/hub/session did not match a known command
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'DESKTOP-L7F0R37', ip: '192.168.0.22', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
remote stacktrace: 
    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.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    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:126)
    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:543)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:117)
    at TesteAutomatizado.main(TesteAutomatizado.java:13)

mas tbm não achei resolução para esse, já baixei diversas versões do Selenium, atualizei os navegadores, já configurei variável de ambiente mas nada funciona.

Eu parei o curso, pq realmente estou empacado nesse erro, olhei o fórum inteiro do curso aqui na Alura e não tem nenhuma dúvida igual que possa me ajudar

solução!

Resolvido, na verdade nao sei o que era, o projeto parece que estava com problema, exclui e fiz outro e agora está funcionando.