如何隐藏Firefox窗口(Selenium WebDriver)? [英] How to hide Firefox window (Selenium WebDriver)?

查看:2716
本文介绍了如何隐藏Firefox窗口(Selenium WebDriver)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我同时执行多个测试时,我不想让Firefox浏览器窗口可见。我可以使用 selenium.minimizeWindow() t想要这样做。

有没有办法隐藏Firefox窗口?我使用的是FireFox WebDriver。最后,我找到了一些解决方案,让那些正在使用windows机器运行测试的人使用任何方法。那么,实现不是在Java中,但你可以很容易地做到这一点。



使用 AutoIt 工具。它具有处理窗口的所有能力。它是免费的工具。


  1. 安装AutoIt:
    http://www.autoitscript.com/site/autoit/downloads/


  2. 打开编辑器,在下面的代码中写下
    来隐藏任何窗口。

      AutoItSetOption(WinTitleMatchMode,2)
    WinSetState(窗口标题,,@SW_HIDE)

  3. $

    $ p $ AutoItSetOption(WinTitleMatchMode)使用下面的代码行来取消隐藏。 ,2)
    WinSetState(窗口标题,,@SW_SHOW)

    WinTitleMatchMode 有不同的选项可用于匹配Windows标题。

      1 =从开始匹配标题(默认)`
    2 =匹配标题中的任何子字符串
    3 =精确的标题匹配
    4 =高级模式,请参阅窗口标题& Text(Advanced)


是:我已经创建了一个小程序的EXE和传递参数作为命令行参数如下。
$ b $ pre $ Runtime.getRuntime()。读信息范范范范范范范范内范程中范信信端亦范信范范范信范范范信范范范亦信信信信信亦信信信信信端信信信信信端信信信信中上范信信中上亦中信息范秘

HideNSeek.exe - 我有以下的AutoIt代码:

  AutoItSetOption(WinTitleMatchMode,1)

如果$ CmdLine [0]> 0然后
if $ CmdLine [1] == 0然后
WinSetState($ CmdLine [2],,@SW_HIDE)
ElseIf $ CmdLine [1] == 1然后
WinSetState($ CmdLine [2],,@SW_SHOW)
其他
EndIf
EndIf

$ CmdLine [] 是一个包含所有命令行参数的数组。

  $ CmdLine [0] =参数个数
$ CmdLine [1] = Exe名称后的第一个参数


如果窗口标题中有任何空格,则必须使用双引号将其作为命令行参数如上。



下面的代码行将执行AutoIt exe,如果我在第一个参数中传递'0',它将隐藏窗口,如果我将传递'1',那么它将取消隐藏匹配标题的窗口。

  Runtime.getRuntime()。exec(C:/Diiinnovation/HideNSeek.exe 0 \+Mozilla Firefox+\);预范信息预读信息中的信息亦范范信范亦预辛辛的数亦亦亦预秘范信息中信息谢谢!


When I execute multiple test simultaneously, i don't want to keep Firefox browser window visible.. I can minimize it using selenium.minimizeWindow() but I don't want to do it.

Is there any way to hide Firefox window? I am using FireFox WebDriver.

解决方案

Finally I found the solution for those who is using windows Machine for running the Tests using any method. Well, implementation is not in java but you can do it very easily.

Use AutoIt tool. It has all the capability to handle windows. It is free Tool.

  1. Install AutoIt: http://www.autoitscript.com/site/autoit/downloads/

  2. Open the Editor and write below code for Hiding any window.

    AutoItSetOption("WinTitleMatchMode", 2)
    WinSetState("Title Of Your Window", "", @SW_HIDE) 
    

  3. To Unhide it, you can use below line of code.

    AutoItSetOption("WinTitleMatchMode", 2)
    WinSetState("Title Of Your Window", "", @SW_SHOW)
    

    WinTitleMatchMode has different options which can be used to match Windows title.

    1 = Match the title from the start (default)`
    2 = Match any substring in the title
    3 = Exact title match
    4 = Advanced mode, see Window Titles & Text (Advanced)
    

So what I am doing is: I have created exe of a small program and passing parameter as command line argument as below.

Runtime.getRuntime().exec("C:/Diiinnovation/HideNSeek.exe 0 \"" + "Mozilla Firefox" + "\"");

in HideNSeek.exe - I have below AutoIt Code:

AutoItSetOption("WinTitleMatchMode", 1) 

if $CmdLine[0] > 0 Then
    if $CmdLine[1] == 0 Then
        WinSetState($CmdLine[2], "", @SW_HIDE)    
    ElseIf $CmdLine[1] == 1 Then
        WinSetState($CmdLine[2], "", @SW_SHOW)          
    Else    
    EndIf   
EndIf

$CmdLine[] is an array which will have all command line parameters..

$CmdLine[0] = number of Parameter
$CmdLine[1] = 1st Parameter after Exe Name 
.
.

If there is any space in the Window Title then you have to use double quotes to pass it as a command line parameter like above.

Below Line of code will execute AutoIt exe and if I pass '0' in 1st parameter then it will hide the window and if I will pass '1' then it will unhide windows matching the title.

Runtime.getRuntime().exec("C:/Diiinnovation/HideNSeek.exe 0 \"" + "Mozilla Firefox" + "\"");

I hope this will help you. thanks!

这篇关于如何隐藏Firefox窗口(Selenium WebDriver)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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