佟希吧 关注:5贴子:18
  • 0回复贴,共1
import java.util.concurrent.TimeUnit;import org.junit.*;import org.junit.Test;import static org.junit.Assert.*;import org.openqa.selenium.*;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.interactions.Actions;import org.openqa.selenium.support.ui.Select;public class Baidu {private WebDriver driver;private String baseUrl;@Beforepublic void setUp() throws Exception {System.setProperty("webdriver." + "firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");driver = new FirefoxDriver();// baseUrl = "http://bbs.a9vg.com";driver.manage().window().maximize();driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);}@Test// By.id// By.name// By.className// By.linkText// By.xpathpublic void testBaidu1() throws Exception {// WebDriver driver = new FirefoxDriver();driver.get("http://www.baidu.com/");assertEquals(driver.getTitle(), "百度一下,你就知道");System.out.print(driver.findElement(By.linkText("新闻")).getText());assertEquals(driver.findElement(By.linkText("新闻")).getText(),"新闻");driver.findElement(By.linkText("新闻")).click();assertEquals(driver.getCurrentUrl(), "http://news.baidu.com/");/*String taobao=driver.getWindowHandle();WebElement element = driver.findElement(By.linkText("天猫"));element.click();driver.switchTo().window(taobao);WebElement element2 = driver.findElement(By.id("q"));element2.sendKeys("aaa");WebElement element3 = driver.findElement(By.id("J_TSearchForm"));element3.submit();//WebElement element2 = driver.findElement(By.id("su"));/*element.clear();element.sendKeys("selenium");Select select = new Select(driver.findElement(By.name("exp")));select.selectByVisibleText("有经验");WebElement checkbox = driver.findElement(By.name("check"));if(!checkbox.isSelected()){checkbox.click();}*//*Actions action = new Actions(driver);action.sendKeys(element2, "abc");Thread.sleep(1000);action.click(element2);action.perform();*//*driver.get(baseUrl + "/");// driver.findElement(By.linkText("天猫")).click();WebElement element1 = driver.findElement(By.xpath(".//*[@id='lsform']/div/div/table/tbody/tr[2]/td[3]/NOtton"));element1.click();driver.findElement(By.xpath("html/body/div[2]/p[3]/a")).click();Select select = new Select(driver.findElement(By.xpath(".//*[@id='phone']")));select.selectByIndex(1);/* * driver.findElement(By.name("q")).sendKeys("月饼"); * driver.findElement(By.className("search-button")).click(); */}/* * @After public void tearDown() throws Exception { driver.quit(); } */}
胡博


来自iPhone客户端1楼2016-10-24 15:28回复