Thanks for the post on using Selenium WebDriver with Perl. Been using Selenium IDE for awhile, just started experimenting with the WebDriver today, and I am still relatively new to programming. How do you add the Selenium::Remote::WebElement functions to a Perl script? A simple example, something like a Google search, would be great.
Interacting with elements in WebDriver is slightly different from how it was done in RC. The most basic pattern would be using
$driver->find_element($locator, $typeOfLocator);, which returns a WebElement. You can even chain the WebElement command onto the find_element if you’d like:
On my OS X box with Selenium Server 2.25.0 running, the following script opens up Firefox, goes to google.com, inputs “hello, anon” in the search bar, and then Google Instant kicks in and shows me a page of results without even having to hit enter or click submit.
#! /usr/bin/perl use strict; use warnings; use Selenium::Remote::Driver; my $driver = new Selenium::Remote::Driver(); $driver->get("http://www.google.com"); my $searchBar = $driver->find_element("gbqfq", "id"); $searchBar->send_keys("hello anon"); # uncomment this sleep if you want to visually see anything # happen; otherwise it might be too fast # sleep(10); $driver->quit();
Let me know if that clears things up, or just makes everything more confusing :p