[Selenium] common functions comparison
1.Wait for element in default time or self defined time
When the element need some time to be present , be visible, be not present or be not visible, for example : loading icon, waiting time is very import to get the element.
2.Explicit wait
(1) new WebDriverWait(driver, 10). until(ExpectedConditions.elementToBeClickable(locator));
(2) new WebDriverWait(driver, 10). until(ExpectedConditions.visibilityOf(locator));
(3) new WebDriverWait(driver, 10). until(ExpectedConditions.presenceOfElementLocated(locator);
(4)
Function<WebDriver, WebElement> waitFn = new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return el.findElement(By.cssSelector("div.rptstatus.rptcomplete"));
}
};
//Detect every 2 seconds, the maximum time is 120 seconds
WebDriverWait wait = new WebDriverWait(driver, 120, 2);
wait.withMessage("A processing icon should display in the Status column in the row.”)
wait.until(waitFn);
3.waitForElementVisible VS waitForElementPresent
5.Some element might be Present/Visible, it also might not. But both conditions are correct.
For example : alert dialog
In this condition, we need to use try{ ...} catch()
6.Find element under another element
permissionEl.findElement(By.cssSelector("input[value='true']"))
SeleniumUtil.waitForElementVisible(driver, By.cssSelector(".top-bottom-split"), workSpaceEl);
public void catchIfPopUpDialogAndClickClose(){
try{
SeleniumUtil.waitForElementVisible(driver, By.cssSelector("input#btnClose")).click();
logger.info("Dialog pops up");
}
catch(Exception e)
{
logger.info("No dialog pops up");
}
}
[Selenium] common functions comparison的更多相关文章
- selenium.common.exceptions.TimeoutException: Message: Screenshot: available via screen
在使用selenium+phantomjs的时候在Windows平台下能够正常工作,在Linux下却不能,并得到错误信息: selenium.common.exceptions.TimeoutExce ...
- selenium使用遇到的问题(selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.)
1.安装pip3 install selenium 2.使用browser=webdriver.Chrome()时报错 :selenium.common.exceptions.WebDriverExc ...
- python+selenium,打开浏览器时报selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
有一年多没写web自动化了,今天搭建环境的时候报了一个常见错误,但是处理过程有点闹心,报错就是常见的找不到驱动<selenium.common.exceptions.WebDriverExcep ...
- 【Selenium】【BugList7】执行driver.find_element_by_id("kw").send_keys("Selenium"),报错:selenium.common.exceptions.InvalidArgumentException: Message: Expected [object Undefined] undefined to be a string
[版本] selenium:3.11.0 firefox:59.0.3 (64 位) python:3.6.5 [代码] #coding=utf-8 from selenium import webd ...
- 关于Selenium.common.exceptions.WebDriverException: Message: Invalid locator strategy: css selector 的问题
在执行脚本时报Selenium.common.exceptions.WebDriverException: Message: Invalid locator strategy: css selecto ...
- appium selenium.common.exceptions.WebDriverException: Message: Parameters were incorrect
selenium.common.exceptions.WebDriverException: Message: Parameters were incorrect. We wanted {" ...
- selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None;Message: unexpected alert open: {Alert text : 您点击的频率过快!请稍后再试}
报错 Traceback (most recent call last): File "C:/myFiles/code/cnki/cnki_1/core/knavi.py", li ...
- selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary
使用Chrome浏览器时,经常会遇到以下报错:浏览器没有调用起来 selenium.common.exceptions.WebDriverException: Message: unknown Err ...
- selenium.common.exceptions.ElementNotVisibleException: Message: element not visible处理方法:selenium针对下拉菜单事件的处理
使用Selenium爬虫时,可能会遇到一些下拉菜单,动态加载,如果直接使用find_element_by_函数会报错,显示selenium.common.exceptions.ElementNotVi ...
随机推荐
- ubuntu下不同版本python安装pip及pip的使用
由于ubuntu系统自带python2.7(默认)和python3.4,所以不需要自己安装python. 可以使用python -V和python3 -V查看已安装python版本. 在不同版本的py ...
- 533. Lonely Pixel II
Given a picture consisting of black and white pixels, and a positive integer N, find the number of b ...
- 接口自动化测试之HTTP协议详解
协议 简单理解,计算机与计算机之间的通讯语言就叫做协议,不同的计算机之间只有使用相同的协议才能通信.所以网络协议就是为计算机网络中进行数据交换而建立的规则,标准或约定的集合. OSI模型 1978年国 ...
- 【swagger】1.swagger提供开发者文档--简单集成到spring boot中【spring mvc】【spring boot】
swagger提供开发者文档 ======================================================== 作用:想使用swagger的同学,一定是想用它来做前后台 ...
- IDEA中Thrift插件配置
方法一:直接在IDEA界面中配置 打开IDEA的插件中心,搜索 Thrift 即可安装 方法二:手动下载Thrift插件安装 有时像在IDEA中安装Lombok插件一样,有时由于网络原因,方法一不奏效 ...
- 生活娱乐 360安全卫士和QQ大战
360安全卫士指控QQ侵犯用户隐私 [提要]9月26日晚上11点16分,安全软件商360在他们的论坛中发布了最新公告:<360安全卫士发布隐私保护器 专门曝光"窥私"软件&g ...
- 学习Android之第六个小程序新浪微博(二)(ListView和TabActivity)
效果图例如以下: 选项卡的使用: 1.继承TabActivity 2.声明TabHost变量,通过方法getTabHost()获取并赋值. (TabHost tabHost =getTabHost( ...
- 键值对集合Dictionary<K,V>根据索引提取数据
Dictionary<K,V>中ToList方法返回 List<KeyValuePair<K,V>>定义可设置检索的键/值对
- hibernate载入持久化对象的两种方式——get、load
一.get与load对照 在hibernate中get和load方法是依据id取得持久化对象的两种方法.但在实际使用的过程中总会把两者混淆,不知道什么情况下使用get好,什么时候使用load方法效率更 ...
- HDU 1248 寒冰王座 (水题的N种做法!)(含完全背包)
寒冰王座 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...