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. [Inside HotSpot] Serial垃圾回收器 (二) Minor GC

    Serial垃圾回收器Minor GC 1. DefNewGeneration垃圾回收 新生代使用复制算法做垃圾回收,比老年代的标记-压缩简单很多,所有回收代码都位于DefNewGeneration: ...

  2. delphi学习路线

     酷派(53376063) 11:04:19 1.语法基础PASCAL精要 先看个1-3遍,这是基础中的基础,只要没弄清楚看10遍都不多,当然最好结合着代码实例去看.(以后遇到哪儿不熟练继续反复看)2 ...

  3. android 拍照预览

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  4. iOS开发之计算两个日期的时间间隔

    //首先创建格式化对象  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDate ...

  5. leetcode笔记:Contains Duplicate

    一. 题目描写叙述 Given an array of integers, find if the array contains any duplicates. Your function shoul ...

  6. C#总结复习5(需要进一步复习)

    第十五章 接口 1.接口: C++中允许多继承没有接口的概念.而java与C#中有,因为C#中 是单继承多接口. 所谓的接口,其实和抽象类.方法相似.都只有一个空方法.其本身不可以为基类,但是允许被其 ...

  7. zedboard中OLED源码

    #include <stdio.h> #include "platform.h" #include "xil_types.h" #include & ...

  8. 【转载】图说OOP基础(一)

    本文用图形化的形式描述OOP的相关知识.对OOP进行系统化的梳理,以便掌握. 涉及知识点: OOP的相关知识 OOP知识[Object-Orientation Programming 面向对象编程]总 ...

  9. PHP中include路径修改

    1.__FILE__ __FILE__ always equals to the real path of a php script regardless whether it's included. ...

  10. 用C++、Qt实现的小游戏2048

    窗口布局与游戏截图: 实现思路: 1.使用二维数组模拟整个游戏网格,并将二维数组中每个数的大小用作游戏中每个网格中的数据. 2.将对游戏的数据及数据的操作(即玩家的操作对游戏数据的影响)作为一个类,游 ...