Firefox "Mouseover" issues in Selenium Ruby bindings on Windows - ruby

I've been struggling with mouse hover for a couple of days and found a couple of threads here on the topic, but none have helped. I've tried dozens of different approaches and have also modified my code to be more in sync with the examples here, especially Dave Haeffner's suggestions. The current code looks like:
Selenium::WebDriver::Wait.new(timeout: 2).until do
#driver.find_element(link: "ADMIN").displayed?
end
#driver.action.move_to(#driver.find_element(link: "ADMIN")).perform
Selenium::WebDriver::Wait.new(timeout: 2).until do
#driver.find_element(link: "ORGANIZATION").displayed?
end
driver.action.move_to(#driver.find_element(link: "ORGANIZATION")).perform
Selenium::WebDriver::Wait.new(timeout: 2).until do
#driver.find_element(link: "TEAMS").displayed?
end
#driver.find_element(link: "TEAMS").click
end
On macs, this code works fine. On Windows however, it produces:
Failure/Error: #driver.action.move_to(#driver.find_element(link: "ADMIN")).perform
Selenium::WebDriver::Error::InvalidElementStateError:
Cannot perform native interaction: Could not load native events component.
I'm sure the element access is fine, because if I change the first mouse hover to a click action, it works great.
Any help would be appreciated.

You need to use Firefox version 31.0.6 . Versions of Firefox after that don't have the native events support. If you need to use a later version of Firefox, then just make sure your test actions are all non-native, such as using a JavascriptExecutor to create a hover (instead of relying on native events in the firefox driver).

Related

protractor dragAndDrop not working on Mac

I am executing my protractor code on MAC OS system and using Chrome. Everything works but not drag and drop event.
The code is working fine if I put my actual mouse position on the target of drop. But if the actual mouse position is not at the target location, its not performing the action.
The code I am using is as:
browser.actions().dragAndDrop(source,target).perform();
I have also tried this :
browser.actions().mouseDown(source).mouseMove(target).mouseUp().perform();
Use html-dnd NPM module.
Link:https://www.npmjs.com/package/html-dnd
code snippet:
var dragAndDrop = require('html-dnd').code;
var draggable = driver.findElement(By.id('draggable'));
var droppable = driver.findElement(By.id('droppable'));
driver.executeScript(dragAndDrop, draggable, droppable);
for this :
browser.actions().dragAndDrop(source,target).perform();
try this :
browser.actions().mouseMove(source).mouseDown().mouseMove(target).mouseUp().perform();
Note that dragAndDrop is nothing but mouseMove + mouseDown + mouseMove + mouseUp
Chances are you're in a long line of people who have problems with the drag and drop functionality implemented with html5. This has been a problem area to work around using Selenium webdriver.
Please see that the issue might be due to an age old bug that was filed for ChromeDriver.
The bug has a lot of discussion that may be helpful in understanding the real issue and there are also a lot of solutions mentioned in the comments below - however there has not been a fool-proof or 100% working solution to this problem.
This bug has been mentioned in Protractor github issues a lot of times like here, here, here,and here and in Selenium GitHub in the archived issues here.
One of the solutions you can try is this helper method that was created here. However this is not a guaranteed solution, but I would suggest you to give it a try. The original issue mentioned for Protractor here also has many other solutions mentioned which you can try. You can also try this helper method.
Also, please see that the same question has been posted multiple times here, here, here, here.

Test success differences in different browsers

When attempting to click elements using a CSS selector, e.g
browser.find_element(:css, '.login').click
I am seeing different behaviours in different browsers. This is the behaviour I am seeing:
Chrome (35.0.1916.114) - works as expected
Firefox (24.0) - seems to ignore the command and move onto the next line of the test. Either that or it thinks it has clicked the element when it has not.
Safari (7.0.3 (9537.75.14) - complains that the element is not present. Interestingly, this one doesn't even seem to wait until the page has even loaded.
I have tried using a variety of web driver versions (2.42.0, 2.39.0, 2.33.0) and different browser versions with no success.
It turns out that my specific problem was that Firefox doesn't like targeting link elements inside lists, whilst chrome will do it fine. For example:
The following will not work in Firefox:
Browser.find_element(:css, '.list-item')
Whereas this will:
Browser.find_element(:css, '.list-item > a')
This may have been a unique problem for the site I was testing, but it is worth bearing in mind.

Selenium Firefox 19 CSS Menu Click Not Working

Using Selenium, with an earlier combo of the webdriver (2.28.0) and Firefox (pre-19), the following code worked.
driver.get("http://www.haemonetics.com/en");
driver.findElement(By.linkText("LOGIN")).click();
driver.findElement(By.linkText("Haemonetics")).click();
With webdriver 2.31.0 and Firefox 19.0.2 the code does not work and I receive a NoSuchElementException for the second findElement.
I tried using xpath which doesn't work for Firefox but does work for Chrome and IE, which are part of the same test suite.
Any thoughts or another way to accomplish the same thing? I would prefer to use the same code for the mentioned browsers.
Not sure if it was a typo on your part, but it should be "find_element" instead of "findelement", at least it's so in 2.31 to my knowledge.
Try
driver.find_element_by_link_text("LOGIN")
if that doesn't work, post your HTML code so we can possibly construct a working Xpath.

console.log is not working when used in a Firefox, Greasemonkey script

My userscript prints some information using console.log().
This works fine in Chrome, but when I install this userscript in Firefox (Greasemonkey), the web console in Firefox is not displaying anything.
I searched for a solution and some suggested to use unsafeWindow but it is also not showing any output. Moreover unsafeWindow cannot be used for chrome. I even installed Firebug but it was no use. How can I resolve this?
For example, I tried this userscript in Firefox:
// ==UserScript==
// #name console
// ==UserScript==
console.log("hello");
You mean it doesn't work when installed via Greasemonkey, right?
Not long ago, Greasemonkey broke console.log (New! Bug report). Now, to see the results of a plain console.log() call from a Greasemonkey, you need to look in Firefox's Error console, not Firebug's.
You can see FF's Error console by pressing: CtrlShiftJ.
However, you can use unsafeWindow.console.log() in both Chrome and Greasemonkey scripts. Chrome now has limited support for unsafeWindow.
If you use unsafeWindow, you have access to the full range of Firebug's logging functions from Greasemonkey. (Firebug must be installed and they still might not work in Chrome userscripts; I haven't tested that way in a while.)
In Firefox, if Firebug is not installed, or it is not active for the page, then unsafeWindow.console.log() calls will display to the New "Web Console" (CtrlShiftK).
You need to use the unsafeWindow when inside a Greasemonkey script.
Note that Firefox currently supports console.log(), console.info(), console.warn(), and console.error() natively -- no Firebug required.
Wait a minute: if the question is about logging in the console with Greasemonkey (I could swear I saw the tag greasemonkey), why not use the GM_log method?
// ==UserScript==
// #name GM_log Example
// #namespace http://www.example.com/
// ==/UserScript==
GM_log("This is an example of GM_log");
Or am I missing something?
PS: you can also check for javascript.options.showInConsole in about:config. it should be true.
I found that (testing with Chrome/Tampermonkey) you need:
window.log("<message goes here>");, not unsafeWindow.console.log("<msg>");,
as unsafeWindow and console come up as undefined.
Try that, as I'm pretty sure that's the way you're supposed to do it in later versions of browsers, etc.

Unable to trigger mouse event in Capybara test

I am using Capybara 1.0.0, and I have a link in my page which gets visible when mouse hover over that block. So I want to trigger mouse over in test so that I can click that hidden link.
I googled it, but couldn't find the solution that suits me. Can you guys help me with this?
I've chosen to use Capybara webkit, and sadly I had to resort to executing javascript using jQuery:
page.execute_script('$(".ClassSelector").trigger("hover")')
This blog has the answer:
http://aokolish.me/blog/2012/01/22/testing-hover-events-with-capybara
page.find('#element').trigger(:mouseover)
This doesn't work with the selenium driver though:
http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Element#trigger-instance_method
This commit added the hover method. It has the advantage of including css hover effects on elements.
Usage:
find('#posts .post .comments .comment').hover
I had a lot of trouble getting this to work as well. There's a lot of conflicting information on the web. Here's how I did it:
Setting: rails 3.2.1, capybara 1.1.2, rspec 2.8.0, selenium-webdriver 2.20.0
page.execute_script "$('tr.user-#{user.id}').trigger('mouseover')"
This will cause the previously hidden links to appear (by virtue of jQuery's hover function), which are then accessible for have_link and click_link.
Note: you do not want to write page.evaluate_script as this won't work.
Edit: Well I just realized that #kelly-sutton's solution is the same as mine. So I can confirm this.
For visibility problems sometimes it helps to change window size for poltergeist. I've done it
in spec_helper.rb
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, window_size: [1280, 600])
end
As well as using either find('#element').hover or page.execute_script "$('#element_2').trigger('mouseover');" one must also pass js: true to the describe block in order to turn on javascript (unless you've done that in your configuration). This tripped me up for a bit.

Resources