selenium webdriver学习历程(一)------------快速开始 .

上一篇 / 下一篇  2012-11-27 11:54:54 / 个人分类:Selenium

51Testing软件测试网uZ3h#K/U0Y

学习selenium已经两年了,从1.X到2.X,一直在关注它。中间由于工作原因中断了一段时间,但是一直无法割舍,最近又去官网看了一下,更新还挺快的。selenium1.X的时代将被取代,selenium-webdriver的大航海时代开始了。。。

W,nt&C2f@J~e0

51Testing软件测试网({L D p0gW{wYR

安装selenium webdriver(eclipse+jdk+selenium webdriver2.20+firefox 10)

51Testing软件测试网Pe9V?%Xj ]

1、安装firefox,本人使用firefox10。确保firefox安装在默认环境下(不是的话会报错)。51Testing软件测试网IG7yp {-Oyo4B(l!b'B

51Testing软件测试网3I*|_&H7CF8X"W:Zv

2、安装jdk,确保安装了jdk,本人喜欢使用java。但selenium webdriver也支持其它语言,如ruby、python、C#等。

8H:T(Of:}v` [/x4R051Testing软件测试网9a{Iv9Tx(c/nFhU

3、安装eclipse,个人喜好。51Testing软件测试网RAw,I.Vw qZ|

-B H;J"Z,yeuf}04、安装selenium webdriver。解压下载的selenium webdriver包,可以在eclipse建一个user library,便与项目的引入。51Testing软件测试网#ol |M)l&BL7H

51Testing软件测试网D)q;K7z?c

 

*v@r.\L,z*c s0

0gzx%rhvU-z0 

\s%v-CKz!H0

第一个test

9Idp*["II*B0现在以第一个selenium webdriver的test来感受一下它的魅力。51Testing软件测试网"w2y|c&e2a S1`D,v

Java代码  收藏代码
  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.WebDriver;  
  3. import org.openqa.selenium.WebElement;  
  4. import org.openqa.selenium.firefox.FirefoxDriver;  
  5.   
  6.   
  7. public class FirstExampe {  
  8.   
  9.       
  10.     public static void main(String[] args) {  
  11.         WebDriver driver = new FirefoxDriver();  
  12.   
  13.          
  14.         driver.get("http://www.google.com.hk");  
  15.         WebElement element = driver.findElement(By.name("q"));  
  16.         element.sendKeys("hello Selenium!");  
  17.         element.submit();  
  18.         try {  
  19.             Thread.sleep(3000);  
  20.         } catch (InterruptedException e) {  
  21.             e.printStackTrace();  
  22.         }  
  23.         System.out.println("Page title is: " + driver.getTitle());  
  24.        
  25.         driver.quit();  
  26.     }  
  27.   
  28. }  
 51Testing软件测试网:RO%y"@:P^

正常运行后,这几行代码将会打开firefox浏览器,然后转跳到google首页。在搜索框中输入hello  Selenium并提交搜索结果。等待3秒后会在命令行打印出当前页面的title,输出如下:51Testing软件测试网z vazA/ju"S

Java代码  收藏代码
  1. Page title is: hello Selenium! - Google 搜尋  
51Testing软件测试网 { fY5q`z$H0F

 并关闭ff浏览器。51Testing软件测试网Y}&IXv

51Testing软件测试网 l2T$A[&Gs

51Testing软件测试网3p`+`a!r u"Wa

KbOmb+X#^051Testing软件测试网nfe3s Q$g

转自:http://www.51testing.com/?uid-486521-action-viewspace-itemid-81508151Testing软件测试网k-oY*E4k]}0Ff
51Testing软件测试网F!vV\T1y*C:G


TAG:

kujie0121的个人空间 引用 删除 kujie0121   /   2012-11-28 09:06:57
-1
 

评分:0

我来说两句

Open Toolbar