changeset 10:83e16df2288a

still experimenting
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 07:52:02 -0700
parents d09937a6cb4b
children 24ff8a9c76c4
files browser.pl main-firefox.pl play-browser.py refresh-browser.py
diffstat 4 files changed, 42 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser.pl	Tue Oct 25 07:52:02 2011 -0700
     1.3 @@ -0,0 +1,18 @@
     1.4 +#!/usr/bin/perl
     1.5 +
     1.6 +
     1.7 +use WWW::Selenium;
     1.8 +
     1.9 +my $sel = WWW::Selenium->new( host => "localhost",
    1.10 +			      port => 4444,
    1.11 +			      browser => "*firefox",
    1.12 +			      browser_url => "http://www.google.com",
    1.13 +			    );
    1.14 +
    1.15 +$sel->start;
    1.16 +$sel->open("http://www.google.com");
    1.17 +$sel->type("q", "hello world");
    1.18 +$sel->click("btnG");
    1.19 +$sel->wait_for_page_to_load(5000);
    1.20 +print $sel->get_title;
    1.21 +$sel->stop;
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/main-firefox.pl	Tue Oct 25 07:52:02 2011 -0700
     2.3 @@ -0,0 +1,8 @@
     2.4 +#!/usr/bin/perl
     2.5 +
     2.6 +use WWW::Mechanize::Firefox;
     2.7 +my $mech = WWW::Mechanize::Firefox->new();
     2.8 +$mech->get('http://google.com');
     2.9 +
    2.10 +$mech->eval_in_page('alert("Hello Firefox")');
    2.11 +my $png = $mech->content_as_png();
     3.1 --- a/play-browser.py	Tue Oct 25 05:33:36 2011 -0700
     3.2 +++ b/play-browser.py	Tue Oct 25 07:52:02 2011 -0700
     3.3 @@ -9,11 +9,21 @@
     3.4  # Create a new instance of the Firefox driver
     3.5  #driver = webdriver.Firefox()
     3.6  
     3.7 -driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.FIREFOX)
     3.8 -
     3.9 +driver = webdriver.Remote("http://localhost:7055/wd/hub", webdriver.DesiredCapabilities.FIREFOX)
    3.10  
    3.11  # go to the google home page
    3.12  driver.get("http://tycho.usno.navy.mil/cgi-bin/timer.pl")
    3.13  
    3.14 -# you HAVE to quit if you're reusing firefox sessions
    3.15 +time.sleep(2)
    3.16 +
    3.17 +driver.refresh()
    3.18 +
    3.19 +time.sleep(2)
    3.20 +
    3.21 +driver.refresh()
    3.22 +
    3.23 +time.sleep(2)
    3.24 +
    3.25 +
    3.26 +
    3.27  driver.quit()
     4.1 --- a/refresh-browser.py	Tue Oct 25 05:33:36 2011 -0700
     4.2 +++ b/refresh-browser.py	Tue Oct 25 07:52:02 2011 -0700
     4.3 @@ -5,6 +5,8 @@
     4.4  from selenium.common.exceptions import TimeoutException
     4.5  from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
     4.6  import time
     4.7 +import sys
     4.8 +
     4.9  
    4.10  # Create a new instance of the Firefox driver
    4.11  #driver = webdriver.Firefox()
    4.12 @@ -13,7 +15,7 @@
    4.13  
    4.14  
    4.15  # go to the google home page
    4.16 -driver.get("http://tycho.usno.navy.mil/cgi-bin/timer.pl")
    4.17 +driver.get(sys.argv[1])
    4.18  
    4.19  # you HAVE to quit if you're reusing firefox sessions
    4.20  driver.quit()