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.

*
*SeleniumUtil.waitForElementNotVisible(driver, By.cssSelector("div#window-waiting-box"),"Waiting box should disppear in default time which is configured as timeOutInSeconds in environment.xml");
*SeleniumUtil.waitForElementNotVisible(driver, By.cssSelector("div#window-waiting-box"), 120 ,"Waiting box should disappear in 120s");
 

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

*SeleniumUtil.waitForElementVisible(driver, By.cssSelector("input#btnClose"), "Close button exists but not visible")
*
*SeleniumUtil.waitForElementPresent(driver, By.cssSelector("input#btnClose"), "Close button doesn’t exist")
 
4.waitForElementPresent   VS   waitForAllElementsPresent
*WebElement element = SeleniumUtil.waitForElementPresent(driver, By.cssSelector("input[value='"+buttonName+"']"),"Cannot get button named: "+buttonName);
*
*List<WebElement> elementList = SeleniumUtil.waitForAllElementsPresent(driver, By.cssSelector("div.rtq-grid-row[rowid]"),"Cannot get folders list");
 

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的更多相关文章

  1. selenium.common.exceptions.TimeoutException: Message: Screenshot: available via screen

    在使用selenium+phantomjs的时候在Windows平台下能够正常工作,在Linux下却不能,并得到错误信息: selenium.common.exceptions.TimeoutExce ...

  2. 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 ...

  3. python+selenium,打开浏览器时报selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

    有一年多没写web自动化了,今天搭建环境的时候报了一个常见错误,但是处理过程有点闹心,报错就是常见的找不到驱动<selenium.common.exceptions.WebDriverExcep ...

  4. 【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 ...

  5. 关于Selenium.common.exceptions.WebDriverException: Message: Invalid locator strategy: css selector 的问题

    在执行脚本时报Selenium.common.exceptions.WebDriverException: Message: Invalid locator strategy: css selecto ...

  6. appium selenium.common.exceptions.WebDriverException: Message: Parameters were incorrect

    selenium.common.exceptions.WebDriverException: Message: Parameters were incorrect. We wanted {" ...

  7. 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 ...

  8. selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary

    使用Chrome浏览器时,经常会遇到以下报错:浏览器没有调用起来 selenium.common.exceptions.WebDriverException: Message: unknown Err ...

  9. selenium.common.exceptions.ElementNotVisibleException: Message: element not visible处理方法:selenium针对下拉菜单事件的处理

    使用Selenium爬虫时,可能会遇到一些下拉菜单,动态加载,如果直接使用find_element_by_函数会报错,显示selenium.common.exceptions.ElementNotVi ...

随机推荐

  1. 安装破解版的webstorne

    参考以下链接:https://www.cnblogs.com/cui-cui/p/8507435.html

  2. Lighttpd 服务器的安装

    https://www.cnblogs.com/rongfengliang/articles/3503228.html

  3. noip2015提高组day2解题报告

    1.跳石头 题目描述 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 N 块岩石( ...

  4. Codeforces 123 E Maze

    Discription A maze is represented by a tree (an undirected graph, where exactly one way exists betwe ...

  5. centos的python2.6.x升级到python2.7.x方法;python2.6.x的版本就不要用了

    python2.6.x的版本,现在使用的很多插件都不支持了.所以如果你的centos还是使用的2.6.x版本,不要犹豫,赶紧升级到2.7.x版本 1.所谓升级,就是再安装一个python2.7.x版本 ...

  6. linux操作系统下查看某rpm包是32bit 还是x64bit的命令

    [root@hosta ~]# rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" | grep l ...

  7. CCPhysicsSprite

    #ifndef __PHYSICSNODES_CCPHYSICSSPRITE_H__ #define __PHYSICSNODES_CCPHYSICSSPRITE_H__ #include " ...

  8. c 链表之 快慢指针 查找循环节点(转)

    上面分析了 根据这张图 推倒出 数学公式. 刚接触 不能一下弄明白.下面结合上面文章的分析.仔细推倒一下 , 一般设置 快指针 速度是 慢指针的2倍.及 快指针每次遍历两个指针, 慢指针每次遍历1个指 ...

  9. 从头学起-CLR的执行模型

    1.将源代码编译成托管代码 公共运行时(Common Language Runtime) a.面向运行时的所有语言都可以通过异常报告错误 b.面向运行时的所有语言都可以创建线程 c.核心功能:管理内存 ...

  10. Cocos2d-x 精灵碰撞检測(方法一)

    声明函数碰撞检測函数,两个精灵和重写update bool isCollision( CCPoint p1,CCPoint p2,int w1,int h1,int w2,int h2 ); CCSp ...