我正在为我的工作申请一个从我们的网络应用程序中提取数据的应用程序。我正在尝试使用Selenium连接到该网站,但我收到了SessionNotCreatedException
。以下是在孤立环境中导致问题的原因:
public void testDriver() {
System.setProperty("webdriver.gecko.driver", "C:\\data\\brandonw\\Desktop\\Docs\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http//user:pass@flag.60north.net/");
}
我最初认为这是初始连接时来自我们网页的身份验证提示的问题。使用Jsoup,我通常只使用一个基本的身份验证标头,但是对于Selenium,我发现放置用户并以上述格式传入url是解决方案。身份验证似乎不是问题。
我在网上发现的下一个潜在原因是我的Firefox,Selenium或Geckodriver(三者的任意组合)都不是最新的。以下是我目前正在使用的内容:
Firefox:v58 硒:v3.8.1 geckodriver:0.19.1
根据我在github上看到的内容,geckodriver 0.19.0支持Firefox 55.0+和Selenium 3.5+,所以它似乎也不是版本问题。我现在对这可能是什么感到难过。我的堆栈跟踪如下:
1517250905541 geckodriver INFO geckodriver 0.19.1
1517250905561 geckodriver INFO Listening on 127.0.0.1:32904
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'MKT-PC01', ip: '192.168.3.184', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x47e934 - <no info>
1: 0x47f0a3 - <no info>
2: 0x442511 - <no info>
3: 0x4436da - <no info>
4: 0x42a890 - <no info>
5: 0x406f5e - <no info>
6: 0x40cfc9 - <no info>
7: 0x6bef19 - <no info>
8: 0x420756 - <no info>
9: 0x6b96e0 - <no info>
10: 0x773859cd - BaseThreadInitThunk
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:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
at com.brandon.MagnaScraper.MagnaSurveyPage.extractQ(MagnaSurveyPage.java:112)
at com.brandon.MagnaScraper.MagnaSurveyPage.getQ(MagnaSurveyPage.java:59)
at com.brandon.MagnaScraper.App.main(App.java:54)
提前感谢你们提供的任何帮助!
编辑:作为一个额外的想法,我也尝试了32位和64位的geckodriver。
答案 0 :(得分:0)
使用所有二进制文件 Firefox:v58 , Selenium:v3.8.1 和 geckodriver:0.19.1 进行正确配置并查看错误如:
10: 0x773859cd - BaseThreadInitThunk
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
BaseThreadInitThunk
是在初始化/创建新线程期间运行的初始化函数。这是将调用线程起始地址的函数,这意味着:
因此,我认为你错过了下列其中一项的强制导入,你必须添加它们:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;