Selenium(webdriver)实战

版本firefox41.0.2

Selenium2.48.2

代码下载地址:http://pan.baidu.com/s/15JaFG

关键代码如下:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.bj58.webdriver.demo</groupId>
	<artifactId>webdriverdemo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>webdriverdemo</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>


		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>2.48.2</version>
		</dependency>

	</dependencies>
</project>

test.java

package com.bj58.webdriver.demo.webdriverdemo;

import java.util.concurrent.TimeUnit;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class WebDriverDemoTest  {
	WebDriver driver;

	@Before
	public void setUp() throws Exception {
	      System.out.println("init...");
	        //用 Chrome
//	      System.setProperty(
//	              "webdriver.chrome.driver",
//	              "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
//	      driver = new ChromeDriver();
		// 如果火狐浏览器没有默认安装在C盘,需要制定其路径
		System.setProperty("webdriver.firefox.bin",
				"E:\\tools\\迅雷\\Mozilla Firefox\\firefox.exe");
		driver = new FirefoxDriver();
        //用 IE
//      driver = new InternetExplorerDriver();
		
	}

	@Test
	public void testTest() throws Exception {

//		 driver.get("http://www.baidu.com/");
		driver.get("http://www.baidu.com/");
		// driver.manage().window()

		 WebElement txtbox = driver.findElement(By.name("wd"));
		 txtbox.sendKeys("Glen");
		
		 WebElement btn = driver.findElement(By.id("su"));
		 btn.click();
		 
		 for(int i=0;i<100;i++){
			 txtbox = driver.findElement(By.name("wd"));
			 
			 txtbox.clear();
			 txtbox.sendKeys(i+"");
			 btn.click();
			Thread.sleep(3000);
		 }

		// driver.close();
	}

}
//Browser 	Selenium IDE 	Selenium 1 (RC) 	Operating Systems
//Firefox 3.x 	Record and playback tests 	Start browser, run tests 	Windows, Linux, Mac
//Firefox 3 	Record and playback tests 	Start browser, run tests 	Windows, Linux, Mac
//Firefox 2 	Record and playback tests 	Start browser, run tests 	Windows, Linux, Mac
//IE 8 	Test execution only via Selenium RC* 	Start browser, run tests 	Windows
//IE 7 	Test execution only via Selenium RC* 	Start browser, run tests 	Windows
//IE 6 	Test execution only via Selenium RC* 	Start browser, run tests 	Windows
//Safari 4 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Mac
//Safari 3 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Mac
//Safari 2 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Mac
//Opera 10 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Opera 9 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Opera 8 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Google Chrome 	Test execution only via Selenium RC 	Start browser, run tests 	Windows, Linux, Mac
//Others 	Test execution only via Selenium RC 	Partial support possible** 	As a


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值