简体   繁体   English

Selenium Grid:如何使用RemoteWebDriver和ChromeDriver最大化浏览器窗口

[英]Selenium Grid: how to maximize browser window using RemoteWebDriver and ChromeDriver

I would like to know how can I maximize the browser window using Selenium Grid and RemoteWebDriver with the most popular browsers. 我想知道如何使用Selenium Grid和RemoteWebDriver与最流行的浏览器最大化浏览器窗口。

This question has not been solved yet in this community, there is another question that could look like this: How do I maximize the browser window in Selenium WebDriver (Selenium 2) using C#? 这个问题在这个社区尚未解决,还有一个问题可能如下: 如何使用C#在Selenium WebDriver(Selenium 2)中最大化浏览器窗口? But in that question is not clear how to maximize the browser window in RemoteWebDriver. 但在那个问题尚不清楚如何在RemoteWebDriver中最大化浏览器窗口。

On Firefox and IE I guess it is in the same way driver.manage().window().maximize(); 在Firefox和IE上我猜它的方式与driver.manage().window().maximize();

In Chrome we have to do: 在Chrome中我们必须这样做:

ChromeOptions options = new ChromeOptions(); options.AddArgument("--start-maximized"); driver = new ChromeDriver(options);

The question is how can I apply that to RemoteWebDriver? 问题是如何将其应用于RemoteWebDriver?

If i understand your question correctly you want to know how to pass driver options to remote driver.In that case where ever you are creating driver object you need to create desire capabilities and use one of the constructor of the remote driver with capability parameter. 如果我正确理解你的问题你想知道如何将驱动程序选项传递给远程驱动程序。在这种情况下,你需要创建驱动程序对象,你需要创建欲望功能并使用带有功能参数的远程驱动程序的构造函数之一。 For example 例如

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

ChromeOptions options = new ChromeOptions(); 
options.addArguments("--start-maximized"); 

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

driver = new RemoteWebDriver(URL, capabilities);
//driver = new ChromeDriver(capabilities);

You also can use QAF which abstraction driver configuration and management outside the code. 您还可以在代码之外使用QAF抽象驱动程序配置和管理。 Where you can set driver capabilities by using properties. 您可以使用属性设置驱动程序功能 As alternate You also can use Driver listener for such purpose. 作为备用您也可以使用Driver侦听器来实现此目的。 For example: 例如:

Using Properties: 使用属性:

Following two properties will do the needful for chrome driver: 以下两个属性将需要chrome驱动程序:

drive.name=chromeDriver
chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}

For remote driver: 对于远程驱动:

remote.server=<remote server or grid url>
drive.name=chromeRemoteDriver
chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}

Using Listener: 使用Listener:

void beforeInitialize(Capabilities capabilities){
    if(capabilities.getBrowserName().equalIgnorCase("chrome"){
        ChromeOptions options = new ChromeOptions(); 
        options.addArguments("--start-maximized"); 
        ((DesiredCapabilities)capabilities).setCapability(ChromeOptions.CAPABILITY, options);
    }
}

void onInitialize(QAFExtendedWebDriver driver){
   //for browser other than chrome...
   driver.manage().window().maximize();
}

In Java you could do it like this: 在Java中你可以这样做:

ChromeOptions options = new ChromeOptions(); 
options.addArguments("--start-maximized"); 
RemoteWebDriver driver = new ChromeDriver(options); 

It was already hinted at in the comments but to point it out: You can assign a ChromeDriver instance to a RemoteWebDriver type. 它已在评论中暗示过,但要指出:您可以将ChromeDriver实例分配给RemoteWebDriver类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Selenium 2 RemoteWebDriver与ChromeDriver结合使用 - Using Selenium 2 RemoteWebDriver with ChromeDriver Chrome 浏览器 window 在 Selenium-grid 节点中未最大化 - Chrome Browser window is not maximize in Selenium-grid node Selenium Grid:使用RemoteWebDriver自定义浏览器位置 - Selenium Grid: Use custom browser location with RemoteWebDriver 如何使用Java使用氦气最大化浏览器窗口? - How to maximize browser window with helium using Java? 如何为Selenium Grid设置chromedriver? - How to set chromedriver for Selenium Grid? 如何在 selenium 2 WebDriver 中找到当前使用窗口是最大化还是最小化? - How to find the whether the current using window is maximize or minimize in selenium 2 WebDriver? Chromedriver和Selenium框架-实例化chromedriver后即会打开浏览器窗口 - Chromedriver and the Selenium framework - browser window opens as soon as chromedriver is instantiated 将FireFoxProfile与RemoteWebDriver一起使用,Selenium Grid2会导致功能异常 - Using FireFoxProfile with RemoteWebDriver, Selenium Grid2, causes Capabilities Exception 在Selenium中使用命令“ driver.manage()。window()。setPosition(new Point(0,-1000));”之后,无法最大化浏览器 - Not able to maximize browser after using the command “driver.manage().window().setPosition(new Point(0,-1000));” in Selenium 如何在Selenium RemoteWebDriver中设置浏览器版本? - How can I set the browser version in Selenium RemoteWebDriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM