Selenium webdriver Selenium WebDriver使用PhantomJSOptions设置PhantomJS初始viewportSize

Selenium webdriver Selenium WebDriver使用PhantomJSOptions设置PhantomJS初始viewportSize,selenium-webdriver,phantomjs,Selenium Webdriver,Phantomjs,使用.net下的Selenium WebDriver,当PhantomJS启动时,默认的viewportSize是400 px宽300 px高。是否可以在创建之前使用PhantomJSOptions增加默认视口大小 以下是我尝试过的,但似乎没有任何效果: PhantomJSOptions opts = new PhantomJSOptions(); opts.AddAdditionalCapability("phantomjs.page.viewportSize", "{ wi

使用.net下的Selenium WebDriver,当PhantomJS启动时,默认的viewportSize是400 px宽300 px高。是否可以在创建之前使用PhantomJSOptions增加默认视口大小

以下是我尝试过的,但似乎没有任何效果:

    PhantomJSOptions opts = new PhantomJSOptions();

    opts.AddAdditionalCapability("phantomjs.page.viewportSize", "{ width: 1024, height: 768 }");
以下是创建驱动程序后可用的替代方法:

driver.Manage().Window.Size = new System.Drawing.Size(1024,768);

使用WebDriver设置窗口大小

driver.set_window_size(1024,68)
如果你真的想,也许可以这样:

var phantomJSDriverService = PhantomJSDriverService.CreateDefaultService(phantomJsDir);
phantomJSDriverService.phantomjs.page.viewportSize = "{ width: 1024, height: 768 }";
var driver = new PhantomJSDriver(phantomJSDriverService);

我希望在创建之前将初始大小设置为“driver”。这个解决方案设置了创建后的大小。我看到了。但是为什么呢?通常的顺序是创建浏览器实例、调整其大小、删除cookie等,然后导航到某个地方。如果你按照你的建议去做,你会得到什么?两个原因(1)我通常的顺序不包括调整大小或cookies。当我创建一个Chrome或Firefox实例时,它被最大化并准备就绪,所以我希望在创建它时我的PhantomJS实例的大小合理。另外(2)我想通过示例学习如何使用PhantomJSOptions来指定我在chrome和firefox中看到的PhantomJS设置,在创建后必须最大化,但好奇是一个很好的理由。为什么要否决?