如何在启动 Selenium Remote Control 期间调整 Firefox 窗口大小/最大化?

发布于 2024-08-06 06:12:04 字数 198 浏览 6 评论 0原文

我正在使用 Selenium 远程控制 。在执行测试期间,实际的 Firefox 窗口非常小。我希望它全屏显示,这样我就可以看到正在发生的事情。如何最大化浏览器屏幕?

I am using Selenium Remote Control . During executing the tests the actual Firefox window is so small. I want it full screen so I can see what is happening. How can I maximize the browser screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

<逆流佳人身旁 2024-08-13 06:12:04

尝试 windowMaximize 命令:

selenium.windowMaximize();

您还可以使用以下命令设置特定的宽度和高度:

selenium.getEval("window.resizeTo(X, Y); window.moveTo(0,0);")

其中 X 是宽度,Y 是高度。

Try the windowMaximize command:

selenium.windowMaximize();

You can also set a specific width and height using the following command:

selenium.getEval("window.resizeTo(X, Y); window.moveTo(0,0);")

Where X is the width and Y is the height.

微暖i 2024-08-13 06:12:04

这对我有用。所有其他解决方案在 FF7 中均不起作用。

WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
driver.manage().window().setPosition(new Point(0, 0));
driver.manage().window().setSize(new Dimension(1920, 1080));

This works for me. All the other solutions didn't work in FF7.

WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
driver.manage().window().setPosition(new Point(0, 0));
driver.manage().window().setSize(new Dimension(1920, 1080));
捶死心动 2024-08-13 06:12:04

您可以执行以下操作:

page.driver.browser.manage.window.maximize

You can do the following:

page.driver.browser.manage.window.maximize
孤云独去闲 2024-08-13 06:12:04

硒2.31.0

driver = webdriver.Firefox()

# Resize the window to the screen width/height
driver.set_window_size(300, 500)

# Move the window to position x/y
driver.set_window_position(200, 200)

Selenium 2.31.0

driver = webdriver.Firefox()

# Resize the window to the screen width/height
driver.set_window_size(300, 500)

# Move the window to position x/y
driver.set_window_position(200, 200)
も让我眼熟你 2024-08-13 06:12:04

对于火狐浏览器:
sel.key_press_native(122)
(F11 的按键代码为 122)

for Firefox:
sel.key_press_native(122)
(122 in the key code for F11)

只是一片海 2024-08-13 06:12:04

好吧,我认为最好的方法是使用 selenium.windowMaximize() selenium 函数而不是操纵窗口大小。

Well I think the best way is to use selenium.windowMaximize() selenium function instead of manipulating the windows size.

陌上青苔 2024-08-13 06:12:04

-singlewindow 参数传递给 Selenium RC 服务器时,提供的所有答案都不起作用。但是,如果您将 Firefox 配置文件传递到 Selenium RC 服务器 (详细说明如下),您可以创建一个空的配置文件文件夹并将此文件放入该文件夹中:

localstore.rdf(区分大小写的文件名!)

<?xml version="1.0"?>
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
                   sizemode="normal"
                   height="9999"
                   width="9999"
                   screenX="0"
                   screenY="0" />
                   lastSelected="paneTabs" />
  <RDF:Description RDF:about="chrome://browser/content/browser.xul">
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#main-window"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#PersonalToolbar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#nav-bar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#status-bar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#toggle_taskbar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#navigator-toolbox"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#toolbar-menubar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-box"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-title"/>
  </RDF:Description>
</RDF:RDF>

将宽度和高度替换为您首选的宽度和高度。 9999x9999 几乎可以最大化任何显示器。

以这种方式运行 Selenium RC 服务器的最简单的示例假设我们的主目录中有前面提到的 localstore.rdf,并且我们当前位于 Selenium RC 服务器的目录中:

rm -rf ~/ffProfile
mkdir ~/ffProfile
cp localstore.rdf ~/ffProfile
java -jar selenium-server-*.jar -singlewindow -firefoxProfileTemplate "~/ffProfile"

这也有不“污染”您的测试的额外好处。

None of the answers provided work when passing the -singlewindow parameter to the Selenium RC server. However, if you pass a firefox profile to the Selenium RC server (as detailed somewhat here), you can make an empty profile folder and put this file in the folder:

localstore.rdf(case sensitive filename!):

<?xml version="1.0"?>
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
                   sizemode="normal"
                   height="9999"
                   width="9999"
                   screenX="0"
                   screenY="0" />
                   lastSelected="paneTabs" />
  <RDF:Description RDF:about="chrome://browser/content/browser.xul">
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#main-window"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#PersonalToolbar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#nav-bar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#status-bar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#toggle_taskbar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#navigator-toolbox"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#toolbar-menubar"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-box"/>
    <NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-title"/>
  </RDF:Description>
</RDF:RDF>

Replace width and height with your preferred width and height. 9999x9999 will pretty much maximize any monitor.

The simplest example possible of running your Selenium RC server this way assuming we have the previously mentioned localstore.rdf in our home directory, and we are currently in the directory of the Selenium RC server:

rm -rf ~/ffProfile
mkdir ~/ffProfile
cp localstore.rdf ~/ffProfile
java -jar selenium-server-*.jar -singlewindow -firefoxProfileTemplate "~/ffProfile"

This also has the added benefit of not "polluting" your tests.

深海夜未眠 2024-08-13 06:12:04

为了扩展 David Hunt 关于更具体的窗口大小调整和移动的建议,请注意以下内容。

要在大多数环境中工作,请在调整大小之前先移动。那是:

selenium.getEval("window.moveTo(X, Y); window.resizeTo(X, Y); ")

覆盖屏幕的 2/3,这对于查看下面的 selenium 驱动窗口的一部分很方便,并且可以执行以下操作无论您的目标屏幕分辨率如何:

selenium.getEval("window.moveTo(screen.availWidth / 3,0); window.resizeTo(screen.availWidth * (2/3), screen.availHeight); ");

To expand on David Hunt's suggestion for more specific window resizing and moving note the following.

To work in most environments move before resizing. That is:

selenium.getEval("window.moveTo(X, Y); window.resizeTo(X, Y); ")

To cover 2/3's of the screen, which is handy for seeing part of the selenium driving window underneath, and to do this regardless of your target screen resolution:

selenium.getEval("window.moveTo(screen.availWidth / 3,0); window.resizeTo(screen.availWidth * (2/3), screen.availHeight); ");

少女的英雄梦 2024-08-13 06:12:04

在 ruby​​ 中,调用将是

web_driver.manage.window.maximize

In ruby, the call would be

web_driver.manage.window.maximize

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文