Watir::IE.attach(:title,/x/) not working correctly on Win 7 IE8
System: Window 7 Internet Explorer 8 Ruby 1.8 Watir 1.6.5
If I manually open a browser window and then visit a site that causes a second browser window to open and then use the Watir::IE.attach method to find the second browser window everything work fine. The problem is when I open the first Internet Explorer window with the command Watir::IE.new and then visit a site that causes a second browser window to open. When I use Watir::IE.attach to find the second browser window I now get: Watir::Exception::NoMatchingWindowFoundException: Unable to location a window with title of (?-mix:x) from /ie-class.rb:297:in 'attach_browser_window' from /ie-class.rb:149:in '_attach_init' from /ie-class.rb:143:in 'attach' from (irb):15
Has anyone run into this problem and developed a solution?
I have done a little more investigating and I am running my script with administrative rights, and it is opening IE8 as administrator and then trying t开发者_运维知识库o open a new window. I tried to open IE8 as administrator manually and then open a new window from the browser then run the attach command with watir and I did get the same error as if I created the initial window with watir.
I do want to be able to run my script as administrator.
I have tried executing the watir command manually and also running in a script:
======================
require 'rubygems'
require 'watir'
ie = Watir::IE.start("http://www.quackit.com/html/codes/html_open_link_in_new_window.cfm")
ie.link(:text,"HTML Help").click
ie2 = Watir::IE.attach(:title,/Help/)
======================
Right now watir assumes that the window you want to attach to is called "Internet Explorer". I think the name of the IE8 might be different from this. You can change this on line 238 of ie-class.rb.
Bret
Turn off User Account Control (set to the lowest setting). Go to Control Panel->System and Security->Action Center->Change User Account Control settings, and drop the slider to the lowest setting.
I was experiencing the same issue, and this fixed it for me.
I'm getting the same issue. I've investigated it a little bit more, and the issue seems to be that when there already exists an instance of IE8 that was opened with adminstrative privs, Watir won't see any other IE8 windows that are being run as admin, including ones it opens itself.
I came to this realization by doing this:
Watir::IE.each do |window|
puts window.title
end
The cases I tried out were:
- No previously opened IE windows resulted in watir listing only the new browser, not the one it created (that i wanted to attach to).
- One or more previously opened non-admin IE windows would list the pre-existing browser instances, as well as itself, but again it would not list the new window it spawned.
- One or more previously opened IE windows run as admin was slightly different in that it would list off all of the pre-existing windows, but would not list itself nor any additional windows it created.
Which led me to the conclusion that Watir will not retain in its list any admin-privileged instances of IE8 that it creates after there is an existing admin-privilaged IE8 open.
The solution that I'm using right now is to just not run my scripts as admin. I realize that's not really an option in some cases, but it's the best I've been able to find so far.
精彩评论