简体   繁体   中英

Can I pass the -f parameter to iexplore.exe when using Watir?

I need to run several instances of a Ruby script that's using the Watir gem, and they all need to be able to run in IE fullscreen mode.

CLARIFICATION: They need to be able to open IE in a mode that allows multiple instances of IE to operate in full screen mode, not necessarily trigger the fullscreen. Opening up IE normally allows only a single instance to open fullscreen (not maximized).

I can make this happen manually, by specifying the '-f' parameter on iexplore.exe. Is there a way to make this happen when creating the browser object from Watir?

If I can't make it happen when this as some sort of runtime parameter, I'd be ok with changing the base Watir call that opens IE - if I could and could find it.

require 'watir' 
browser = Watir::Browser.new <--- adding '-f' somehow here?

Try this, it worked for me on IE 9.

browser = Watir::Browser.new
browser.goto 'http://www.google.com'
browser.getIE.parent.FullScreen = true 

Edit: I found a registry setting that may do what you are trying.

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
Fullscreen = "yes" (Default = "no")

-k puts IE into a full screen kiosk mode that is more than F11 . There are no toolbars, menus, icons, etc. You have to hit Alt + F4 to close it and you can Alt + Tab to other open tasks.

Did you try

browser.maximize

It only works on IE, but it is an option that's been documented for a while (see the watir cheat-sheet )

Of course you need perhaps to consider WHY the browser needs to run full screen, or what happens if you move the scripts to a system where the default screen size is different. You might be better off to set the browser to a specific size, which can be done with a simple javascript resizeTo function, you can even 'goto' it as a URL

browser.goto('javascript:resizeTo(800,600)')

There is also a ' moveTo ' that can be used the same way. so you can position the window at a known point.

If you need the browser in a particular place and size, something else to consider would be creating a page with the proper javascript to set things they way you want and then make that your default homepage so it runs as soon as the browser opens. If your google for 'javascript maximize browser' or 'javascript resize browser' you will likely find example code for such a page.

=-=-=-= Edit ( based on clarification that 'fullscreen' is what is wanted, not merely maximized )

Lastly you could look at simply simulating a 'F11' keypress as that is the fullscreen toggle for most browsers. If you are using watir-webdriver this can be done via the sendkeys method

browser.send_keys :f11 

However that is a toggle, and in a script would depend on things being in the right state to start with. Something that got out of sync might end up turning 'off' the fullscreen.

So you might investigate also the idea of a specific page on the local system that would spawn a new fullscreen window, and having the code attach to the new window. (or using the switching window code in watir-webdriver) although this sort of 'popup a new window in fullscreen mode' is something you might expect to be blocked or deprecated (see below) in the future if not already on some browsers.

Warning: being able to throw the browser into fullscreen mode from the HTML is something that is somewhat frowned upon because it is considered a security vulnerability . This is because someone could craft a specific image to make it LOOK like a url bar and other controls were present, and the user at a legitimate site, when creating a phishing site. Such sites are currently one of the larger issues the web community faces right now (contents of my spamfilter are about 20% phishing and rising rapidly) So while there may have been methods in the past to do that, increasingly they get 'shut down' by newer more secure versions of browsers. This might tend to make the sendkeys option your best bet going forward in terms of something that should work cross browser. (nearly all that I know of use F11 for the fullscreen toggle)

Feels hackish, but I figured out I can do something like (but I'd love a better way):

require 'watir'
IO.popen('C:\\Program Files\\Internet Explorer\\iexplore.exe -f "newwindow"')
browser = Watir::IE.attach(:title,/newwindow/)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM