标签:new webdriver query ase manage contain pen before drive
package com.allin.pc;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/*
*
*Ajax浮动框
*/
public class AjaxTest {
WebDriver driver;
String baseUrl;
JavascriptExecutor js;
public static void sleep(double d){
try {
d *= 1000;
Thread.sleep((int)d);
} catch (Exception e) {
// TODO: handle exception
}
}
@BeforeClass
public void setUp(){
baseUrl = "http://www.sogou.com";
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@AfterClass
public void tearDown(){
driver.close();
}
@Test
public void teatAjaxDivOption(){
driver.get(baseUrl);
//首页搜索输入框
WebElement searchInput = driver.findElement(By.id("query"));
//搜索框单击一下
searchInput.click();
sleep(3);
//将浮动框中的所有选项存储到suggetionOptions的list容器中
List<WebElement> suggetionOptions = driver.findElements(By.xpath("//*[@id=‘vl‘]/div/ul/li"));
/*
* 使用for循环遍历容器中所有选项,判断如果某个选项包含“xxxx”这几个关键字
* 则堆这个选项进行单击操作,单击后选项的文字内容会显示在搜索框中,并进行搜索
*/
for(WebElement element: suggetionOptions){
if(element.getText().contains("女神老师组团")){
System.out.println(element.getText());
sleep(3);
element.click();
sleep(3);
break;
}
}
}
}
标签:new webdriver query ase manage contain pen before drive
原文地址:http://www.cnblogs.com/hxm154/p/6165222.html