[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 ...
随机推荐
- 你还在为移动端选择器picker插件而捉急吗?
http://www.cnblogs.com/jingh/p/6381079.html 开题:得益于项目的上线,现在终于有时间来写一点点的东西,虽然很浅显,但是我感觉每经历一次项目,我就学到了很多的东 ...
- 开源天气预报api整理
高德天气:https://lbs.amap.com/api/webservice/guide/api/weatherinfo/? github上对开源api的整理:https://github.com ...
- 转:给 Android 开发者的 RxJava 详解
转自: http://gank.io/post/560e15be2dca930e00da1083 评注:多图解析,但是我还是未看懂. 前言 我从去年开始使用 RxJava ,到现在一年多了.今年加入 ...
- UltraEdit UE如何取消保存文件自动备份
高级-配置-文件处理-备份,设置为不备份
- 适合新人学习的iOS官方Demo
UICatalog.包括了绝大部分经常使用的UI,入门必备良药. 9 分段选择器 10滑动条 Slider 11stack view 12 分步条 13 开关 14 textfield 15text ...
- FSB总线、HT总线、QPI总线、DMI总线
http://wenku.baidu.com/link?url=d0NQFyvVpU--FpQUIjkPcdE036riitKgKib3385qr7VdB1oNUcIDpRndY-HH4ITjzJln ...
- PHP-MySQL,PHP-MySQLi,PDO的差异
PHP-MySQL是PHP操作MySQL数据库最原始的Extension ,PHP-MySQLi的i代表Improvement ,提供了更加高级的功能,就Extension而言,本身也增加了安全性.而 ...
- break 用法
// break 在循环中的功能测试 # include <stdio.h> int main(void){ int i, j; for (i = 0; i<3; ++i) { j ...
- AliYunDun关闭
停止阿里云盾AliYunDun服务解决大量写磁盘问题-小内存ECS服务器 阿里云数据库在没备案,涉及大量IO操作时会自动启动阿里云盾这个服务,会导致服务器变得很卡 关闭服务: service aegi ...
- Spark-1.5.2之改动源代码后的自己定义打包编译
Spark-1.5.2之自己定义打包编译,基于当前最新版本号的spark源代码1.5.2版本号. 自己编译spark是改动spark源代码的必备条件,改动的源代码自己定义打包生效后才干公布到生产环境中 ...