selenium script for mouse hovering using Ruby - ruby

I am using Ruby on Rails to automate website. I am stuck on mouse hover and click action. I have to write code e.g. following website
http://www.sainsburys-live-well-for-less.co.uk/meal-planning/
I need to automate by hovering then clicking on Occasion > summer
Following code i have written but it does not work
*menu = driver.find_element(:id => "Occasion")
submenu = driver.find_element(:id => "summer")
driver.action.move_to(menu).click(submenu).perform*
This code gives error "undefined local variable or method 'driver'".
please suggest.

Related

VB6 - break program until a button is clicked

I'm using VB6 and I'm trying to do the following:
I have a command button that execute a while statement. in this statement I'm loading a new form with:
Load FrmPayment
FrmPayment.Show
I want the program to brake until I click a button in the new form, and then start from the same point I left
I tried looking the web for an answer but couldn't find anything that helped.
How can I do this?
By showing your new form modally the new form is the only form in your application that responds to the user.
Load FrmPayment
FrmPayment.Show vbModal

ruby watir-webdriver cannot access popup

Hi All I am having problems accessing a form with in a popup window that is opened after I click on a link. I appears once I have clicked the link it causes the script to hang and will not even time out. I need to be able to access the form, set some text fields and the click the submit button.
Link code:
<a id="ctl00_ContentPlaceHolder2_ctrlPageHeader1_aFilter" class="RightTextHeading" onclick="javascript:openMdlWindow('InvestmentDetailOptions.aspx?IDAssetType=','620','600');if(window.document.RetValue == '2'){window.parent.LoadinIframe('InvestmentDetail.aspx?FromMenu=N&IDAssetType=','Investment Details > Full View','false');}" style="text-decoration:none;">Filter</a>
I have tried everything but nothing seems to work. Has anyone ever came across this before and have a solution?
Thanks
Did you try this:
browser.window(:title => "annoying popup").use do
browser.button(:id => "close").click
end
More information: http://watirwebdriver.com/browser-popups/

Emulate a HTML <button> press within Ruby

There's a website that I want to scrape (FWIW it's svpply) and there's a button that shows up sometimes saying "Show All", it's an HTML <button> element. Is there any way to use Ruby to emulate a click of this button, and get the content of the full page that results after clicking that button, since the button reveals more content?
The "Show All" button triggers a javascript ajax request. The only way to automate that is to use a library that can execute javascript. Libraries such as Mechanize and ScrAPI will not work.
What will work are tools that drive an actual browser such as watir and selenium. I installed watir-webdriver and successfully got it to click the button and show additional products.
require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'svpply.com/editors_pick'
#count products
puts b.elements(:xpath => '//li[#data-class="Product"]').count
#=> 30
#Now click button
show_all = b.button(:id => "btn_all")
show_all.click
sleep 4
#count products again
puts b.elements(:xpath => '//li[#data-class="Product"]').count
#=>60
Mechanize can do this nicely for you.
If the page is reloaded when you press the button, you can, otherwise you need something that can parse javascript. If you understand where the website redirects you after pressing the button (even on the same page but with some parameters set, use firebug for this purpose), you can eventually read what you need.

How to handle pop up/lookup windows in selenium

I am doing some web automation using Selenium RC. Am new to Selenium RC and am facing problems (may be learning curve) while doing automation. I am using java with Eclipse IDE to code selenium RC.
Scenario: I have a screen with a link. while clicking, it will open a lookup window which contains lot of names (grid). Now I have to select a value from grid by directly clicking any row/record. Or I can use search option and select the record. The problems are
my recorded script is NOT responding to pop-up windows.
Is there any command for "double-click" in selenium.
#rs79 - It didn't work for me. Here is my code:
selenium.click("link=eName"); //click the link to open the lookup window
//lookup window
selenium.focus("Associate"); <br>
selenium.waitForPopUp("Associat", "20000");
selenium.selectWindow("Associat");
selenium.type("id=SearchTextBox", "xyz"); //Enter the text in search field of lookup
selenium.click("id=SearchButton"); // click search button on lookup window <br>
Please correct me if I am wrong. Appreciated if anyone give me more suggestions.
Without access to your DOM, I would recommend recording using the IDE, and adapting the right context from the recorded actions into RC. The IDE does a decent job of capturing the context for popups and modals.
After the capture, here are some gotchas:
For iFrames, change the captured frame id to a more generic (css) locator
Be wary about the difference between selectWindow() and selectFrame()
If its a popup not an popup window then you can try the firebug to locate the element or record you want.
Now copy its xpath and use it in your code.
Same problem I have faced and solved by this method as xpath from fire bug is detailed and locates the proper window.
After coping xpath please verify the path has // at starting.
Thanks
This will help to handle salesforce lookups
Iterator it = windows.iterator();
String parentwindow =(String) it.next();
String childWindow =(String) it.next();
// Switch to parent window
driver.switchTo().window(childWindow);
MiscUtils.pauseForElementToBePresent(3000L);
driver.switchTo().frame("your frame NAME/ID");
MiscUtils.pauseForElementToBePresent(3000L);
// your step to perform on child page.
driver.findElement(By.linkText("123Test")).click();
MiscUtils.pauseForElementToBePresent(3000L);
//if popup is getting close automatically switch to parent window otherwise use "driver.quit();" to close popup
driver.switchTo().window(parentwindow);
driver.switchTo().defaultContent();

How to handle new browser pop up after clicking a js button in Watir?

I am trying to using watir in ruby, I am able open a browser,
enter some values to a username/password form, but then I press enter, then I click the submit button (actually it is pressing an enter, it is easiler to code), it would pop up a new browser windows for our application, then I found I have no control to the new browser. What can I do?
In addition to my problem, the new browser window got no menubar, no toolbar, no navigation bar, thus I cannot open the IE developer toolbar to find the name of the element in the webpage in the new browser.
By the way, my app can only support IE.
I tried the attach method, but it does work:
C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb:302:
in `attach_browser_window': Unable to locate a window with title of (?-mix:New browser title) (Watir::Exception::NoMatchingWindowFoundException)
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb
:150:in `_attach_init'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb
:144:in `attach'
from test1.rb:36
Attach method is able to handle new window.
http://rdoc.info/gems/watir/1.8.1/Watir/IE.attach
for example
browser = Watir::Browser.new
browser.text_field(:id,'username').set 'username')
browser.button(:index,1).click
# popped up the new window
popup = Watir::Browser.attach(:title,'Foobar')
If you will use only the popped up window, you can overwrite browser variable instead.
You could try to authenticate like so:
examplehost.com/authentication?user=foo&password=bar
You could also try to remove "target" attribute (which is probably equal to "_blank") of that authentication form ( i'm pretty much sure you should be able to achive this with watir )
EDIT:
Also, there's this option:
ie2 = Watir::IE.attach(:title, ‘New Ie window, opened upon form submit’)
it can also attach by :url instead of :title
ok, there's possibly this solution that might work:
b = Watir::Browser.start "http://yourpage"
b.execute_script("document.getElementById('your-image-id').onClick = function() {}")
so, the idea is to get that image and overwrite it's onclick event

Resources