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~e051Testing软件测试网({LD
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:Zv2、安装jdk,确保安装了jdk,本人喜欢使用java。但selenium
webdriver也支持其它语言,如ruby、python、C#等。
8H:T(Of:}v`
[/x4R051Testing软件测试网9a{Iv9Tx(c/nFhU3、安装eclipse,个人喜好。51Testing软件测试网RAw,I.Vw qZ|
-BH;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 s00g zx%rhvU-z0
\s%v-CKz!H09Idp*["II*B0现在以第一个selenium webdriver的test来感受一下它的魅力。51Testing软件测试网"w2y|c&e2a
S1`D,v
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
-
-
- public class FirstExampe {
-
-
- public static void main(String[] args) {
- WebDriver driver = new FirefoxDriver();
-
-
- driver.get("http://www.google.com.hk");
- WebElement element = driver.findElement(By.name("q"));
- element.sendKeys("hello Selenium!");
- element.submit();
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("Page title is: " + driver.getTitle());
-
- driver.quit();
- }
-
- }
51Testing软件测试网:RO%y"@:P^正常运行后,这几行代码将会打开firefox浏览器,然后转跳到google首页。在搜索框中输入hello
Selenium并提交搜索结果。等待3秒后会在命令行打印出当前页面的title,输出如下:51Testing软件测试网z v azA/ju"S
- Page title is: hello Selenium! - Google 搜尋
51Testing软件测试网{ fY5q`z$H0F 并关闭ff浏览器。51Testing软件测试网Y}&IXv
51Testing软件测试网l2T$A[&Gs51Testing软件测试网3p`+`a!ru"Wa
KbOmb+X#^051Testing软件测试网nfe3sQ$g转自:http://www.51testing.com/?uid-486521-action-viewspace-itemid-81508151Testing软件测试网k-oY*E4k] }0Ff
51Testing软件测试网F!vV\T1y*C:G
收藏
举报
TAG: