How do I use Watir to download a file to a specific location in IE9 - watir

In the older versions of IE, there is a popup window.
In IE9 it's a funny looking bar on the bottom.
Anybody had tried anything that works yet?

The only way for now is sending TABs.
For example with Watir and RAutomation
ww = Watir::IE.attach(:url, /1.1.1.127/)
#Click on download link
ww.link(:text, /Download_link/).click
#Click on 'Save As' in the 'funny looking bar on the bottom'
wrauto = RAutomation::Window.new(:title => ww.title)
wrauto.send_keys("{TAB}")
wrauto.send_keys("{TAB}")
wrauto.send_keys("{DOWN}")
wrauto.send_keys("{DOWN}")
wrauto.send_keys("{ENTER}")
#popup window to save
w = RAutomation::Window.new(:title => /Save As/)
#Direction that you going to save
w.text_field(:class => "Edit", :index => 0).set path_direction
w.button(:value => "&Save").click
RAutomation::Window.new(:title => /complete/).button(:value => "Close").click

Related

Python - open file and display on screen

I was trying to write a program. I'm using tkinter and I've created a label and a menu bar. I would like to open a PDF from the menu bar (HELP --> Instruction for use), but I don't know how. I've tried the module filedialog.askopenfile but it is not appropriate for me because I want to dispay a specific PDF on screen and not browse through them.
Here is the code for the menu bar:
subMenu = Menu (menubar, tearoff = 0)
menubar.add_cascade (label = "Help")
subMenu.add_command (label =" Instruction for use", command = help)
def help ():

Looking for alternative to sleep(30) in watir

I am trying to apply sleep on page loading that works completely fine, but I want to avoid using it and looking for an alternative.
I have tried these options:
#browser.element(:class => 'oo-pricing').wait_until(:timeout => 30)
Watir::Wait #browser.span(:class => 'oo-blp-price').wait_until(:timeout => 30)
My goal is to wait until the text in span is updated.
browser.goto('https://secure.bestprice.rankingsandreviews.com/nc/configurator/307715')
browser.element(:id => 's2id_select_style').click
browser.element(xpath: ".//*[#id='select2-drop']/div/input").send_keys('Convertible LT 1LT', :tab)
browser.element(id: 'edit_color').click
browser.span(text: 'Incentives').click
browser.element(text: "2017 GM Conquest Cash").parent.preceding_sibling.span.click
You are using Chrome driver, Chrome driver automatically closes the browser. If you had used Firefox driver, you would not be having this problem, The solution to your problem is,
Add this code
require 'watir'
caps = Selenium::WebDriver::Remote::Capabilities.chrome(chrome_options: {detach: true})
browser = Watir::Browser.new :chrome, desired_capabilities: caps
And then write your code
browser.element(:id => 's2id_select_style').click
browser.element(xpath: ".//*[#id='select2-drop']/div/input").send_keys('Convertible LT 1LT', :tab)
browser.element(id: 'edit_color').click
browser.span(text: 'Incentives').click
browser.element(text: "2017 GM Conquest Cash").parent.preceding_sibling.span.click
browser.span(text: 'Save & Update').click #Updated
Now your chrome browser would not closing after the program ends.
Find the element that you want, for example:
#browser.element(:class => 'oo-pricing')
Call the wait_until_present method on it:
#browser.element(:class => 'oo-pricing').wait_until_present

wait_while_present not waiting and next element clicking

in my hooks.rb I have
Before do
#browser = Watir::Browser.new :chrome, :switches => %w[--ignore-certificate-errors --test-type --disable-web-security --disable-extensions]
end
And in my account_home.rb page I have:
class AccountHome
include PageObject
button(:billtransfers, :id => 'nav_transfersPayments')
end
I am trying to wait until a div disappears before I click on an element:
When(/^the user navigates to Bills & Transfers \/ Vendors$/) do
#browser.div(:id => 'spinner').wait_while_present
on(AccountHome).billtransfers_element.when_present.billtransfers
on(AccountHome).vendors
sleep 5
end
but I keep getting the below error:
Element is not clickable at point (95, 254). Other element would receive the click: <div id="spinner" class="screenMask">...</div>
It does not seem to be waiting until the div with id 'spinner' is gone. Additionally, if I replace it with sleep instead of wait_while_present, it will wait but then this line:
on(AccountHome).billtransfers_element.when_present.billtransfers
I receive an error message that billtransfers is not a method. I referred to this documentation https://github.com/cheezy/page-object/wiki/Ajax-Calls
So overall, I just want to wait until the div is gone and then it clicks the button. But 1. It is not waiting while present and not clicking the button when present.

Watir rautomation mouse move does nothing

I'm trying to get a hidden element visible. I've tried every mouse event and element selector I can find in Watir. So I'm trying to use RAutomation code that's already within watir. But it seems ineffective.
require 'watir'
#browser = Watir::IE.new
#browser.goto 'samplesite.com'
#browser.rautomation.mouse.move({:x=>210,:y=240})
From this I get the browser to raise to the top, and the console replies nil. But the mouse hasn't moved. Then when I proceed to do
#browser.rautomation.mouse.click
I get a response of 2... which I take as a success of the click. I need to be able to move the mouse to this coordinate.
#browser.rautomation.adapter
returns => :win_32
Can I set it to :autoit in an already established instance of Watir?
Help please.
So, what you're saying is that the mouse does not move at all?
Try this code:
mouse = #browser.rautomation.mouse
puts mouse.position.inspect
mouse.move :x => 100, :y => 100
puts mouse.position.inspect
What is the output?
To use AutoIt adapter, you can do this:
mouse = RAutomation::Window.new(:adapter => :autoit, :hwnd => #browser.hwnd)
mouse.move :x => 100, :y => 100

Bookmarklet approach

I am trying to write a bookmarklet that will bookmark the current page and save the link to the current page in a backend service. When I click this bookmarklet, I want this bookmarklet to show up as a small popup on the top right in browser tab (attach iframe to existing page). This popup will have options to bookmark current page. Also, there will be options search my bookmarks, tag, etc in this popup.
So far, I have not seen any such bookmarklets (from delicioius, pinboard,etc). Although there are bookmarklets to post links to various services, they don't let you search, see the existing list of bookmarks within in the same popup. User is forced to go to the bookmarking site in a new tab to search, etc.
I am wondering is there a reason why bookmarklets (popup within existing page) like this are not done? Are there any security reasons for this? Or will be be blocked by adblockers?
Have a look at these bookmarklets http://googlesystem.blogspot.com/2007/07/useful-google-bookmarklets.html
javascript: (function() {
var a = window,
b = document,
c = encodeURIComponent,
d = a.open("http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + c(b.location) + "&title=" + c(b.title), "bkmk_popup", "left=" + ((a.screenX || a.screenLeft) + 10) + ",top=" + ((a.screenY || a.screenTop) + 10) + ",height=420px,width=550px,resizable=1,alwaysRaised=1");
a.setTimeout(function() {
d.focus()
},
300)
})();

Resources