Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Element#click_no_wait does not click elements in a frame #45

Closed
jkotests opened this issue Nov 24, 2012 · 7 comments
Closed

Element#click_no_wait does not click elements in a frame #45

jkotests opened this issue Nov 24, 2012 · 7 comments

Comments

@jkotests
Copy link
Member

When trying to set a file field that is located within a frame, the "Choose File to Upload" dialog never opens, causing the script to timeout.

This issue does not occur if the file field is not within a frame.

Steps to Reproduce - Using w3schools:

  1. Run the following script (using any existing file for upload):
require 'watir-classic'
browser = Watir::Browser.new
browser.goto('http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_file')
browser.frame(:index, 1).file_field.set('c:\users\jko\desktop\file.txt')

--> Notice that the "Choose File to Upload" dialog never opens and that the following exception occurs.

RAutomation::UnknownWindowException: Window with locator {:index=>0, :title=>/^choose file( to upload)?|Elegir archivos para cargar$/i} doesn't exist or is not visible!
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.7.3/lib/rautomation/window.rb:226:in `rescue in wait_until_present'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.7.3/lib/rautomation/window.rb:224:in `wait_until_present'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.7.3/lib/rautomation/window.rb:214:in `text_field'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/dialogs/file_field.rb:19:in `set_file_name'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/dialogs/file_field.rb:7:in `set'
        from (irb):10
        from C:/Ruby193/bin/irb:12:in `<main>'

Steps to Reproduce - Locally:

  1. Create a file called "file_field.htm", which contains a file field:
<html>
    <body>
        <input type="file" id="myfile" />
    </body>
</html>
  1. Create a file called "main.htm", which includes the above file in a frame:
<html>
    <body>
        <iframe src="file_field.htm">
    </body>
</html>
  1. Set the file field:
require 'watir-classic'
browser = Watir::Browser.new
browser.goto('C:\Users\jko\Desktop\main.htm')
browser.frame.file_field.set 'c:\users\jko\desktop\file.txt'

--> Notice that the RAutomation::UnknownWindowException mentioned above occurs.

Environment:

  • OS: Windows Vista
  • Browser: IE9
  • Ruby: 1.9.3p327
  • Gems: watir (4.0.2), watir-classic (3.3.0), rautomation (0.7.3)
@jkotests
Copy link
Member Author

This appears to be a general issue with using the Element#click_no_wait method for an element within a frame. The same problem can be seen when clicking a button in a frame (using click_no_wait).

The no_wait command that is being generated is:

#no_wait command:
ruby -e "$:.unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib
/watir-classic/win32ole/1.9.3').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/s4t
-utils-1.0.4/lib').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/user-choices-1.1
.6.1/lib').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/subexec-0.0.4/lib').unsh
ift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/mini_magick-3.2.1/lib').unshift('C:/Rub
y193/lib/ruby/gems/1.9.1/gems/win32screenshot-1.0.7/lib').unshift('C:/Ruby193/li
b/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib').unshift('C:/Ruby193/lib/ruby/ge
ms/1.9.1/gems/xml-simple-1.1.2/lib').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gem
s/rautomation-0.7.3/lib').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/win32-pro
cess-0.7.0/lib').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-1.2.0-x86-ming
w32/lib').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/ffi-1.2.0-x86-mingw32/ext
/ffi_c').unshift('C:/Ruby193/lib/ruby/gems/1.9.1/gems/multi_json-1.3.7/lib').uns
hift('C:/Ruby193/lib/ruby/site_ruby/1.9.1').unshift('C:/Ruby193/lib/ruby/site_ru
by/1.9.1/i386-msvcrt').unshift('C:/Ruby193/lib/ruby/site_ruby').unshift('C:/Ruby
193/lib/ruby/vendor_ruby/1.9.1').unshift('C:/Ruby193/lib/ruby/vendor_ruby/1.9.1/
i386-msvcrt').unshift('C:/Ruby193/lib/ruby/vendor_ruby').unshift('C:/Ruby193/lib
/ruby/1.9.1').unshift('C:/Ruby193/lib/ruby/1.9.1/i386-mingw32');require 'C:/Ruby
193/lib/ruby/gems/1.9.1/gems/watir-classic-3.3.0/lib/watir-classic/core';Watir::
FileField.new(Watir::IE.attach(:hwnd, 262508).frame({:tag_name=>['frame', 'ifram
e']}), :tag_name => Array.new << 'file', :unique_number => 1).click!();"

With the command failing at the:

frame({:tag_name=>['frame', 'iframe']})

This part of the command is generated by the Frame#attach_command. The problem appears to be fixed by changing the method to:

def attach_command
  tag_name = @specifiers[:tag_name].join("' << '")
  @container.page_container.attach_command + ".frame(:tag_name => Array.new << '#{tag_name}', :unique_number => #{unique_number})"
end

Which is the way Element#generate_ruby_code is building the element's locator.

I will try to submit a patch tomorrow.

@jarmo
Copy link
Member

jarmo commented Dec 24, 2012

Is this one the same as #49?

@jkotests
Copy link
Member Author

Yes, fixed by #49.

@slvganesh
Copy link

I have a problem where the same click_no_wait is working in my local machine but not in server environment and that too with 2 or more IE instance. With single instance of IE, click_no_wait is working in server environments without any issue. Any help?

@jarmo
Copy link
Member

jarmo commented Apr 13, 2015

I've written a blog post about debugging #click_no_wait problems here http://itreallymatters.net/post/378669758/debugging-watirs-click-no-wait-method-problems - it is definitely quite an old one, but main logic is still the same when it comes to debugging that kind of problems.

@slvganesh
Copy link

Thanks Jarmo, I've narrowed down my problem a bit with your help. Now I have ended up with the below issue:
rescue in attach_browser_window': Unable to locate a window with hwnd of 853530 (Watir::Exception::NoMatchingWindowFoundException)

I noticed that the hwnd seems to be correct (maps to the intended IE instance). This issue happens when I have two IE browsers open. Even Browser.attach :title, /title/ only works with single IE browser window but not with two.

It would be helpful if I get some hints to debug this issue.

@slvganesh
Copy link

My problem is resolved. I found that the Operating System couldn't view/access the second browser window instance and this has been resolved by turning off User Account Control settings to low.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants