如何获取在Ajax方式产生的浮动框中的元素
package cn.gloryroad;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
public class FirstTestNGDemo {
public WebDriver driver;
String baseUrl = "http://www.baidu.com/";
@Test
public void f() {
Navigation navigation = driver.navigate();
navigation.to("https://www.hao123.com");
//进行一次搜索
WebElement search = driver.findElement(By.xpath("//*[@id='search']/div[3]/form/div[1]/div/input"));
search.sendKeys("我");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
search.click();
//存储浮动框中的所有选项
ListsuggetionOptions = driver.findElements(By.xpath("//*[@id='search']/div[3]/form/div[1]/div/div/ul/li"));
for(WebElement element:suggetionOptions){
if(element.getText().contains("我是证人")){
System.out.print(element.getText());
element.click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
@BeforeMethod
public void beforeMethod() {
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
@AfterMethod
public void afterMethod() {
driver.quit();
}
}