Selenium::Remote::Driver - mouse_move_to_location

I’ve been trying to figure out how to use move the mouse in Selenium Webdriver. I’m using perl, so I’m using the Perl bindings obviously - Selenium::Remote::Driver has a function called mouse_move_to_location, and the documentation for that is the same as what is provided officially by the Selenium project, and both weren’t very forthcoming with why I couldn’t get it to work.

I’ve been banging my head against the wall for this one and eventually just gave up, but the whole time the answer was staring me in the face. The syntax for the arguments to this function in the documentation is different from any of the others - it accepts a hash, like {element => $element}, not just a WebElement or a Sizzle locator or anything like that. Sheesh. I feel pretty dumb about that, but at least it’s solved now :)

Selenium WebDriver, Perl, and Saucelabs.

Last year, Selenium introduced WebDriver, an automated browser program that runs the browser in the same way that a user would.  Saucelabs offers a way to test multiple browsers on multiple operating systems in parallel, completely automated, by running the Selenium software and selling time on their servers. Perl is fun. Saucelabs doesn’t have documentation for connecting to their OnDemand service using WebDriver and Perl, so I’d like to explain how to do that. 

Using Gordon Child’s Selenium::Remote::Driver, it’s pretty straightforward to use Perl to run tests on Saucelabs using WebDriver. Get Selenium::Remote::Driver if you don’t have it (sudo CPAN install Selenium::Remote::Driver). 

#! /usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;

my $desc = "perl webdriver bindings and selenium!";

my $login = "loginName";
my $apiKey = "myApiKey";
my $host = "$login:$apiKey\@ondemand.saucelabs.com";

my $driver = new Selenium::Remote::Driver(
'remote_server_addr' => $host,
'port' => "80",
'browser_name' => "firefox",
'version' => "7",
'platform' => "WINDOWS",
'extra_capabilities' => {'name' => $desc},
); $driver->get('http://www.google.com'); print $driver->get_title(); $driver->quit();

Plugin your login name and api key and that should get you up and running. The script opens FF7 on Windows 2003, gets google.com and outputs “Google” as the title of the webpage. 

For anyone using the Selenium RC WWW::Selenium bindings, things are a bit different in Selenium::Remote::Driver - namely, many of the events (clicking, getting information) are done as methods to a new Selenium::Remote::WebElement object, not the selenium driver object. It was a bit of a pain to migrate over, but I think it’s a lot cleaner now. So far, everything I did with WWW::Selenium I’ve been able to duplicate with Selenium::Remote::Driver, and in most cases it’s much simpler and more elegant :)

Page 1 of 1