首页 > Web开发 > 详细

selenium WebDriver 获取浮动框内容并点击

时间:2015-12-07 20:14:28      阅读:309      评论:0      收藏:0      [点我收藏+]
技术分享
如何获取在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();
//存储浮动框中的所有选项
List<WebElement>suggetionOptions = 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();
}

}

selenium WebDriver 获取浮动框内容并点击

原文:http://www.cnblogs.com/Treasa/p/5027099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!