selenium打不开火狐浏览器
我的代码如下:package cn.gloryroad;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;;
public class FirstWebDriverDemo {
public static void main(String[] args){
WebDriver driver;
String baseUrl;
System.setProperty
("webdriver.gecko.driver", "D:\\Tools\\geckodriver.exe");
/*
System.setProperty
("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
*/
driver = new FirefoxDriver();
baseUrl ="http://www.sogou.com/";
driver.get(baseUrl + "/");
driver.findElement(By.id("query")).sendKeys("光荣之路自动化测试");
driver.findElement(By.id("stb")).click();
}
}
error如下:
1498620765532 geckodriver INFO Listening on 127.0.0.1:21490
六月 28, 2017 11:32:45 上午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1498620765864 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1498620776579 Marionette INFO Listening on port 4899
六月 28, 2017 11:32:57 上午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Falling back to original OSS JSON Wire Protocol.
六月 28, 2017 11:32:57 上午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Falling back to straight W3C remote end connection
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@5cb9f472, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@5cb9f472, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'SH-ESBU-DCL', ip: '172.28.19.83', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:259)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:247)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:242)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:238)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127)
at cn.gloryroad.FirstWebDriverDemo.main(FirstWebDriverDemo.java:19)
参考下这篇自己学习https://stackoverflow.com/questions/40172788/unable-to-create-new-remote-session selenium的版本与火狐浏览器的版本不兼容导致的 我给你几个国外网友的回答你可以各自试一下:
1.this issue is solved with geckodriver 0.15 and selenium 3.3 version.
2.This can work out of the box without the desired capability settings. Go to internet options>>Security, click on:'Reset all zones to default level and after that, ensure that the 'Enable protected mode' checkbox is ticked for all the four zones.
3.First, check your default zoom level in Internet Explorer. If it's not 100% then do the following steps:
Open Internet Explorer.
Press Alt + X and then click on Internet Options.
Click on the Advanced tab.
Place a check mark on "Reset Zoom level for new Windows and tab"
Press Apply and ok.
Close and open Internet Explorer window and check if the Default Zoom is set to 100 %.
Once you have done with above steps, add following lines in your code:
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
Now run your program and it should work.
Hope it will help!!
清晨一缕阳光 发表于 2017-6-28 13:43
selenium的版本与火狐浏览器的版本不兼容导致的
谢谢你的回答。不过我的selenium是3.0.1 火狐是54.0的 这两个不兼容吗?你有什么建议吗?谢谢 菜鸟@大虾 发表于 2017-6-28 13:40
参考下这篇自己学习https://stackoverflow.com/questions/40172788/unable-to-create-new-remote-session
谢谢,这上面的没有解决我的问题,还是不行呢 Real_小T 发表于 2017-6-28 13:51
我给你几个国外网友的回答你可以各自试一下:
1.this issue is solved with geckodriver 0.15 and seleniu ...
谢谢,不过不好使,还是不行 如果是版本浏览器不支持,可以参考该网址对应的解决办法http://www.cnblogs.com/heting/p/6053491.html 104~牛牛 发表于 2017-6-28 14:53
如果是版本浏览器不支持,可以参考该网址对应的解决办法http://www.cnblogs.com/heting/p/6053491.html
谢谢,但是不行 本帖最后由 kexinqw11 于 2017-6-29 10:56 编辑
是不是还要个gecko 的driver 已经解决了,我将firefox的版本从54降到了39。已经可以了
谢谢大家的回复 Daisy_dai 发表于 2017-6-29 13:34
已经解决了,我将firefox的版本从54降到了39。已经可以了
谢谢大家的回复
还是版本不兼容啊 ;P dai~zi 发表于 2017-7-4 09:58
还是版本不兼容啊
哈哈,是啊
页:
[1]