当前位置: 首页 > 知识库问答 >
问题:

具有Chrome驱动程序的硒网格(WebDriverExctive:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置)

方河
2023-03-14

我正试图让我的Selenium网格在Chrome驱动程序上运行。

起初我启动了hub和节点:java-jarselenium-server-standalone-2.45.0.jar-角色Hub java-jarselenium-server-standalone-2.45.0.jar-角色节点-Hubhttp://localhost:4444/grid/register

比我启动我的测试:

public class ChromeDriverTest {
    private WebDriver driver = null;
    String  BaseURL,NodeURL;

@Before
public void before() throws Exception{
    BaseURL="http://www.google.com";
    NodeURL="http://localhost:4444/wd/hub";
    File file = new File("C:\\Users\\pushkaryova\\Desktop\\Nexus\\driver\\chromedriver.exe");
    System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
    DesiredCapabilities capa =DesiredCapabilities.chrome();
    capa.setBrowserName("chrome");
    capa.setPlatform(Platform.ANY);
    driver=new RemoteWebDriver(new URL(NodeURL),capa);
}

@Test
public void GoogleSearch() throws Exception {
    driver.get("http://www.google.com");
    WebElement searchBox = driver.findElement(By.xpath("//div[3]/div/input[1]"));
    hightlight(searchBox);
    driver.findElement(By.xpath("//div[3]/div/input[1]")).clear();
    driver.findElement(By.xpath("//div[3]/div/input[1]")).sendKeys("Test");
    driver.findElement(By.xpath("//button")).click();

}

public void hightlight(WebElement webElement) throws InterruptedException {
    for (int i = 0; i < 2; i++) {
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript(
                "arguments[0].setAttribute('style', arguments[1]);",
                webElement, "color: red; border: 3px solid red;");
    }
}

}

然后得到一个错误:org。openqa。硒。WebDriverException:驱动程序可执行文件的路径必须由webdriver设置。铬。驱动程序系统属性

我的代码出了什么问题?

共有3个答案

柴禄
2023-03-14

您可以启动您的节点:

java -jar selenium-server-standalone-2.45.0.jar -role node -hub localhost:4444/grid/register -browser "browserName=chrome,version=ANY,platform=WINDOWS,maxInstances=20" -Dwebdriver.chrome.driver="C:\chromedriver.exe" -maxSession 20
柴辰阳
2023-03-14

这在3.3.1及以上版本中适用

java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -jar selenium-server-standalone-2.45.0.jar -role node -hub localhost:4444/grid/register -browser "browserName=chrome,version=ANY,platform=WINDOWS,maxInstances=20" -maxSession 20

Webdriver路径应该放在-jar选项之前

钱浩荡
2023-03-14

驱动程序可执行文件需要在节点计算机上物理可用。您可以在启动节点时将路径设置为exe

在命令中添加这一行

-Dwebdriver。铬。驱动程序=/chromedriver。exe

我从json文件中配置了它,发现这稍微容易一点

名称为DefaultNode.json的json文件

{
  "capabilities":
      [
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "platform": "WINDOWS",
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": ip,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": ip
  }
}

使用json配置启动节点

java -jar selenium-server-standalone-2.45.0.jar -role webdriver -nodeConfig DefaultNode.json -Dwebdriver.ie.driver=.\IEDriverServer.exe

注意IEDriverServer。exe与json文件放在同一目录中

 类似资料: