Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selenium RemoteWebDriver打开,但ChromeOptions未传递到selenium网格_Selenium_Remotewebdriver_Chrome Options_Desiredcapabilities - Fatal编程技术网

selenium RemoteWebDriver打开,但ChromeOptions未传递到selenium网格

selenium RemoteWebDriver打开,但ChromeOptions未传递到selenium网格,selenium,remotewebdriver,chrome-options,desiredcapabilities,Selenium,Remotewebdriver,Chrome Options,Desiredcapabilities,我一直在尝试使用docker和selenium网格解决RemoteWebDriver和ChromeOptions的一些问题。主要问题在于代理,但我通过代理pac文件将pac文件url作为参数传递到ChromeOptions中,解决了一半问题。下面的代码在docker debug和本地单机版中运行得非常好,但只要我尝试使用网格或部署并使用Bambole运行,驱动程序就会打开,我可以看到ChromeOptions没有被传递,因为poxy pac文件没有被使用,它只是冻结在org.openqa.sel

我一直在尝试使用docker和selenium网格解决RemoteWebDriver和ChromeOptions的一些问题。主要问题在于代理,但我通过代理pac文件将pac文件url作为参数传递到ChromeOptions中,解决了一半问题。下面的代码在docker debug和本地单机版中运行得非常好,但只要我尝试使用网格或部署并使用Bambole运行,驱动程序就会打开,我可以看到ChromeOptions没有被传递,因为poxy pac文件没有被使用,它只是冻结在org.openqa.selenium.remote.ProtocolHandshake createSession。我已经研究了几个星期了,现在我正在努力阻止它。我看到一些帖子不推荐DesiredCapabilities,但我还没有找到一种在没有它的情况下实现ChromeOptions的方法

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("--disable-infobars");
    options.addArguments("--proxy-pac-url= http://ProxyPacURL.com");
    DesiredCapabilities dc = DesiredCapabilities.chrome();
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);

更新到最新的Selenium JAR,确保您的java版本为1.8或更高版本,然后您可以将ChromeOptions传递到驱动程序中,因为DesiredCapabilities已被弃用。我现在能够使用selenium网格运行selenium docker节点,并且所有ChromeOptions参数现在都被传递到容器中

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("--disable-infobars");
    options.addArguments("--proxy-pac-url=http://myPacFile.com");
    options.addArguments("--no-sandbox");
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
试试这个:

const GRID_HOST = 'http://localhost:4444/wd/hub';

var options = new chrome.Options();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");

driver = new webdriver.Builder()
.usingServer(GRID_HOST)
.forBrowser("chrome")
.setChromeOptions(options)
.build()

我也面临同样的问题,我找到了如下解决方案: 我们需要设置“goog:chromeOptions”而不是“chromeOptions”

在Java代码中,出现以下行:

dc.setCapability(ChromeOptions.CAPABILITY, options);
如果导航到ChromeOptions.CAPABILITY,您会注意到它是一个值为“ChromeOptions”的常量。这适用于本地web驱动程序,但不适用于远程web驱动程序(即selenium网格)

只需将上一行更改为:

dc.setCapability("goog:chromeOptions", options);
现在,当您执行Java代码时,它将正常工作,并且您的所有选项也将显示其效果


我遇到了其他页面,例如,其中提到了上述解决方案。

我遇到了上述相同的困难。我使用的是Java1.8、selenium-server-standalone-3.141.59.jar、Chrome76.x和chromedriver。我使用的是上面的确切语法。选项(“--start maximiaxe”,设置日志文件位置等)不会传递给远程web驱动程序。你还需要做其他调整吗??