码迷,mamicode.com
首页 > 其他好文 > 详细

【cl】selenium实例2:打开百度,输入hello world

时间:2015-12-09 19:16:31      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

/*创建的类为junit class*/

package Selenium_lassen;

import static org.junit.Assert.*;

import java.io.File;

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.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

 

public class Case2 {

WebDriver driver;
@Before
public void setUp() throws Exception {
//方法一
// System.setProperty("webdriver.firefox.bin", "D:\\ruanjian\\Firefox\\azml\\firefox.exe");
//方法二
// DesiredCapabilities capability=DesiredCapabilities.firefox();
// capability.setCapability("firefox_binary","D:\\ruanjian\\Firefox\\azml\\firefox.exe");
//driver = new FirefoxDriver(capability);
//方法三
File pathToFirefoxBinary = new File("D:\\ruanjian\\Firefox\\azml\\firefox.exe");
FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
driver = new FirefoxDriver(firefoxbin,null);
}


@Test
public void test() throws Exception{
driver.get("http://www.google.com.hk");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("hello Selenium!");
element.submit();
}

@After
public void tearDown() throws Exception {
System.out.println("Page title is:"+driver.getTitle());
driver.quit();
}

}

【cl】selenium实例2:打开百度,输入hello world

标签:

原文地址:http://www.cnblogs.com/dieyaxianju/p/5033410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!