如何使用 C# 在 Selenium WebDriver (Selenium 2) 中最大化浏览器窗口? [英] How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#?

查看:20
本文介绍了如何使用 C# 在 Selenium WebDriver (Selenium 2) 中最大化浏览器窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以在 C# 中使用 WebDriver (Selenium 2) 来最大化浏览器窗口?

Is there any way to maximize the browser window using WebDriver (Selenium 2) with C#?

推荐答案

将此功能添加到 WebDriver 有一个悬而未决的问题,可在此处跟踪:http://code.google.com/p/selenium/issues/detail?id=174

There's an outstanding issue to add this functionality to WebDriver, which can be tracked here: http://code.google.com/p/selenium/issues/detail?id=174

一种解决方法是使用 JavascriptExector 如下:

A workaround would be to use the JavascriptExector as follows:

public void resizeTest() {
    driver.Navigate().GoToUrl("http://www.example.com/");
((IJavaScriptExecutor)driver).ExecuteScript("window.resizeTo(1024, 768);");
}

这篇关于如何使用 C# 在 Selenium WebDriver (Selenium 2) 中最大化浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆