新的selenium web驱动程序和firefox出错。

时间:2017-04-13 11:26:03

标签: javascript selenium-webdriver selenium-firefoxdriver firefox-driver

我使用的是selenium jar(selenium-server-standalone-3.3.1)和Firefox 43.0.4。和Eclipse版本:Mars.2发布(4.5.2)

当我运行以下代码时

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Links_Count_List {

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver","C:\\Users\\daniel\\Desktop\\Selenium\\geckodriver.exe");
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    //WebDriver driver = new MarionetteDriver(capabilities); 
    WebDriver driver=new FirefoxDriver();   
    driver.get("http://newtours.demoaut.com/");
    WebElement link=driver.findElement(By.linkText("Home"));
    System.out.println(link.getText());
    //link.click();

    List<WebElement> allLInks=driver.findElements(By.tagName("a"));

    System.out.println("Total number of links are "+allLInks.size());

    for(int i=0;i<allLInks.size();i++){
        System.out.println(allLInks.get(i).getText());
    }


}

}

我收到了以下错误消息。我请求任何人帮忙。

控制台

1492082184399   geckodriver INFO    Listening on 127.0.0.1:10506
1492082185052   mozprofile::profile INFO    Using profile path C:\Users\daniel\AppData\Local\Temp\rust_mozprofile.opDtseG9ymZk
1492082185054   geckodriver::marionette INFO    Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args []
1492082185062   geckodriver::marionette INFO    Connecting to Marionette on localhost:59371
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}}], required capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}}]
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'INFONOVUM-39', ip: '192.168.10.66', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_112'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
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:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
at Links_Check.Links_Count_List.main(Links_Count_List.java:18)

1 个答案:

答案 0 :(得分:0)

它似乎是我的兼容性问题。由于您使用的是最新版本的Selenium,请尝试更新您的Firefox浏览器并重新运行脚本。