jarmo / RAutomation

RAutomation
MIT License
100 stars 33 forks source link

File Download issue #16

Closed gwiley closed 12 years ago

gwiley commented 13 years ago

I am using Win7, Ruby 1.8.7 and Watir 1.9.0

I click a download link and the dialog box appears. I want to click the Save button. When I am not using Autoit the code does not attach to the dialog box. When I use Autoit everything functions as expected. The Save As and the Download Complete dialogs work fine. I only have to use Autoit for the initial Save dialog box. The odd thing is when I'm not using Autoit if I click the Ruby command window the non Autoit RAutomation finds the dialog box and it clicks the Save button. If I just do an attach to the browser and click the link it seems to work. It just won't work when it is imbedded in the rest of my script. I know it doesn't make sense but that is what is happening.

This does not work:

window = RAutomation::Window.new(:title => 'File Download') window.button(:value => '&Save').click()

This works:

window = RAutomation::Window.new(:title => 'File Download', :adapter => :autoit) window.button(:value => '&Save').click()

Thanks for gem. When I get over this hump it will make my life a lot easier.

George

jarmo commented 13 years ago

This seems to be some strange timing issue. What IE version are you using?

Try something like this:

15.times do
  puts RAutomation::Window.new(:title => 'File Download').button(:value => '&Save').exists?
  sleep 1
end

Do you see any "true" output? What about "false"?

gwiley commented 13 years ago

I'm using IE8. I actually have to put a sleep(5) first to get the window.exist? to return true. If I don't I get a 60 second timeout error. If I tell it to use Autoit I can take out the sleep(5) and it everything works. It acts like it is trying to push the button. If I click the IE8 window to bring it to the front the Save dialog box comes back to the front. Even though I get an error the Save button is highlighted. The default is the cancel button so it is trying to push the button. I still have to try the code you suggested. Thanks for your help.

Date: Fri, 24 Jun 2011 04:37:24 -0700 From: reply@reply.github.com To: g_wiley@hotmail.com Subject: Re: [RAutomation] File Download issue (#16)

This seems to be some strange timing issue. What IE version are you using?

Try something like this: 15.times do puts RAutomation::Window.new(:title => 'File Download').button(:value => '&Save').exists? sleep 1 end

Do you see any "true" output? What about "false"?

Reply to this email directly or view it on GitHub: https://github.com/jarmo/RAutomation/issues/16#issuecomment-1431804

gwiley commented 13 years ago

I ran the code below and got 15 true's and "timed out after 60 seconds" message. The click did not happen.

15.times do
  puts RAutomation::Window.new(:title => 'File Download').button(:value => '&Save').exists?
  sleep 1
end
RAutomation::Window.new(:title => 'File Download').button(:value => '&Save').click()
gwiley commented 13 years ago

Sorry I didn't want to close this. I am curious if we can find a solution.

jarmo commented 13 years ago

That's really odd then. It means that it finds the button and sends a click event to it, but for some reason it just doesn't get processed by the window itself in the end.

Try something else:

win = RAutomation::Window.new(:title => 'File Download')
puts win.exists?
puts win.title
puts win.text
btn = RAutomation::Window.new(:title => 'File Download').button(:value => '&Save')
puts btn.exists?
puts btn.value
win.close
puts win.exists?

See if you notice anything unusual and if it can close the very same window.

gwiley commented 13 years ago

Below are the results. If I put a sleep(5) before the below code I can get the first win.exists? to come back true. Even though it returns false you can see that the window is visible. If I change win.close to btn.click I get the 60 second timeout and all the display values remain the same and the window does not close.

RESULTS:

false

File Download

Do you want to save this file, or find a program online to open it?Name:filename.iefPublisher:Type:Unknown File TypeFrom:domain.com&Find&SaveCancelAl&ways ask before opening this type of fileWhile files from the Internet can be useful, some files can potentially harm your computer. If you do not trust the source, do not find a program to open this file or save this file. Whats the risk?

true

&Save

false

Date: Thu, 30 Jun 2011 22:34:28 -0700 From: reply@reply.github.com To: g_wiley@hotmail.com Subject: Re: [RAutomation] File Download issue (#16)

That's really odd then. It means that it finds the button and sends a click event to it, but for some reason it just doesn't get processed by the window itself in the end.

Try something else:

win = RAutomation::Window.new(:title => 'File Download')
puts win.exists?
puts win.title
puts win.text
btn = RAutomation::Window.new(:title => 'File Download').button(:value => '&Save')
puts btn.exists?
puts btn.value
win.close
puts win.exists?

See if you notice anything unusual and if it can close the very same window.

Reply to this email directly or view it on GitHub: https://github.com/jarmo/RAutomation/issues/16#issuecomment-1480827

jarmo commented 13 years ago

That makes actually sense, because if you create the Window object then it is created right away and calling #exists? on it will try to locate the window and then returns the result right away too, but calling #title has a method call to #wait_until_present which should block until the window has been found. I'm pretty sure that if you add puts win.exists? right after puts win.title you will get true. Try it out please. If that's the case then the button is located successfully indeed. And if you put btn.click instead of win.close then it doesn't work, right?

Let me know of the results, but it seems to be indeed some strange timing issue...

jarmo commented 12 years ago

Closing this issue. If you still have the problem, then please reopen it, thanks.