selenium 常用的显式等待
来源:互联网 发布:惠普打印机安卓软件 编辑:程序博客网 时间:2024/06/06 03:07
1.实例的html源码
<html><head><title>你喜欢的水果</title></head><body><p>请选择你爱吃的水果</p><br><select name='fruit'><option id='peach' value ='taozi'>桃子</option><option id='watermelon' value='xigua'>西瓜</option></select><br><input type='checkbox'>是否喜欢吃水果?</input><br><br><input type="text" id ="text" value="今年夏天西瓜相当甜!">文本框</input></body></html>
2.java实例代码
//声明一个webdriverWait对象,设定触发条件的最长等待时间为10秒WebDriverWait wait = new WebDriverWait(driver, 10);//调用ExpectedConditions的titleContains方法判断页面Title属性是否包含“水果”两字wait.until(ExpectedConditions.titleContains("水果"));System.out.println("网页标题出现了水果的关键字");//获得页面下拉列表中的桃子选项对象WebElement select = driver.findElement(By.xpath("//option[@id='peach']"));//调用ExpectedConditions的elementToBeSelected方法,判断桃子是否处于选定状态wait.until(ExpectedConditions.elementToBeSelected(select));System.out.println("下拉列表的选项桃子目前处于选中状态");/*调用expectContains的elementtobeclickable方法判断页面的复选框是否可见,并且可以被单击*/wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@type='checkbox']")));System.out.println("页面复选框处于显示可被单击的状态");//调用ExpectedContditions的presenceOfElementLocated的方法判断标签p是否在页面中wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//p")));System.out.println("页面的P标签元素已显示");WebElement p = driver.findElement(By.xpath("//p"));wait.until(ExpectedConditions.textToBePresentInElement(p, "爱吃的水果"));3.自定义显式等待
try {//显式等待判断是否可以从页面获取输入文字的输入框对象,乳沟可以获取,则执行后续逻辑测试WebElement textIputBox = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() {@Overridepublic WebElement apply(WebDriver d){return d.findElement(By.xpath("//*[@type='text']"));}});//断言获取页面输入框中是否包含“今年的西瓜想当甜!”这几个关键字Assert.assertEquals("今年夏天西瓜相当甜!", textIputBox.getAttribute("value"));//判断页面的P标签中是否包含爱吃两个字,若包含则执行后续的测试逻辑Boolean containTextFlag =(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {@Overridepublic Boolean apply(WebDriver d){return d.findElement(By.xpath("//p")).getText().contains("爱吃");}});Assert.assertTrue(containTextFlag);//显式等待判断页面的文本输入框是否可见,若可见则执行后续测试逻辑Boolean inputBoxVisibleFlag = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {public Boolean apply(WebDriver d) {return d.findElement(By.xpath("//*[@type='text']")).isDisplayed();}});Assert.assertTrue(inputBoxVisibleFlag);} catch (NoSuchElementException e) {Assert.fail("页面上的输入框元素未被找到!");e.printStackTrace();// TODO: handle exception}
0 0
- selenium 常用的显式等待
- selenium的webdriver三种等待方式(显式等待WebDriverWait+implicitly_wait隐式等待+sleep强制等待)
- Selenium显示等待和隐式等待的区别
- selenium 的显示等待与隐式等待
- Selenium的延迟等待
- Selenium的延迟等待
- Selenium的延迟等待
- Selenium的延迟等待
- Selenium的延迟等待
- Selenium的延迟等待
- Selenium的延迟等待
- Selenium(Webdriver)显式等待封装
- selenium测试(Java)-- 显式等待
- selenium+Java等待模式(显式等待+隐式等待)
- 【Selenium】9显示等待、隐式等待
- Selenium--显示等待和隐式等待
- Selenium显性等待的方式
- selenium显示等待与隐士等待的区别
- Ubuntu14.04 apache2 CGI 搭建
- 泛型算法04
- Storyboard介绍及使用2 Storyboards Part2 译文
- 怎么在火狐浏览器查看保存的cookie
- python+mongodb==pymongo的源码安装
- selenium 常用的显式等待
- 小鼠迷宫问题
- dfs.name.dir与dfs.data.dir
- c++第一次实验--循环
- 泛型算法05
- [magento]Warning: Your Magento folder does not have sufficient write permissions. If you wish to pro
- unity自带寻路Navmesh
- PRIMARY KEY与identity(1,1)的比较
- HBase -ROOT-和.META.表结构(region定位原理)