caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args"=> ["--window-size=1280,960"]})
url = "http://localhost:9515" # if you are using local chrome or url = Browserstack/ saucelabs hub url if you are using cloud service providers.
Selenium::WebDriver.for(:remote, :url => url, :desired_capabilities => caps)
调整大小铬在最新的铬驱动程序是错误的,它失败与这个故障消息间歇。
unknown error: cannot get automation extension
from timeout: cannot determine loading status
from timeout: Timed out receiving message from renderer: -65.294
(Session info: chrome=56.0.2924.76)
(Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f)
C # 版本的@yonatan-kiron 的答案,以及来自示例代码的 Selenium 的 using语句。
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--window-size=1300,1000");
using (IWebDriver driver = new ChromeDriver(chromeOptions))
{
...
}
[DllImport("user32.dll", SetLastError = true)]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int Width, int Height, bool Repaint);
// Example
MoveWindow(process.MainWindowHandle, 0, 0, windowSize.Width, windowSize.Height, true);