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;
}
}
}
}
相关文章
- Selenium 处理模态对话框
- IE9浏览器弹出重新发送对话框的处理方法
- selenium自动化实施中对windows弹出框的几种常见处理方案
- selenium不同浏览器处理证书(SSL Certificate)的方法
- 自动化测试-12.selenium的弹出框处理
- selenium webdriver从安装到使用(python语言),显示等待和隐性等待用法,切换窗口或者frame,弹框处理,下拉菜单处理,模拟鼠标键盘操作等
- selenium-webdriver(python) (十) 如何处理下拉框
- selenium中的下拉框处理模块Select
- 自动化测试-11.selenium的下拉框处理类Select
- C# 动态创建SQL数据库(二) 在.net core web项目中生成二维码 后台Post/Get 请求接口 方式 WebForm 页面ajax 请求后台页面 方法 实现输入框小数多 自动进位展示,编辑时实际值不变 快速掌握Gif动态图实现代码 C#处理和对接HTTP接口请求