这是我当前的代码:
FirefoxBinary ffox = new FirefoxBinary(firefoxPath);
ffox.setEnvironmentProperty("DISPLAY", ":20");
driver = new FirefoxDriver(ffox, null);
但我还需要将其添加到DRIVER:
DesiredCapabilities dc=new DesiredCapabilities();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
driver =new FirefoxDriver(dc);
在第一段代码中,DRIVER已经采用了2个参数,我该如何添加呢?
最佳答案
FirefoxBinary ffox = new FirefoxBinary(firefoxPath);
ffox.setEnvironmentProperty("DISPLAY", ":20");
driver = new FirefoxDriver(ffox, null);
您当前的代码是创建
FirefoxBinary
的实例,在其中设置一些属性,然后将其与null
一起传递到FirefoxDriver
构造函数中。这与
FirefoxBinary
,FirefoxProfile
构造函数匹配。还有另一个构造函数可让您传递一组
DesiredCapabilites
以及当前的内容:FirefoxBinary ffox = new FirefoxBinary(firefoxPath);
ffox.setEnvironmentProperty("DISPLAY", ":20");
DesiredCapabilities dc =new DesiredCapabilities();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
driver = new FirefoxDriver(ffox, null, dc);
(未经测试的代码)。