鼠标刚好位于下拉列表上面  tooltip显示   导致当点击tooltip后面的菜单栏失败ElementClickInterceptedException  is not clickable at point

数据驱动的自动化经常可能会有根据数据是否有值来执行操作

String data = testData.getxxx()
if(data != null) {
// to do something
}
// instead of it, using JDK8 Optional
Optional.ofNullable(testData.getxxx()).ifPresent( data -> {
/ /to so something
})

Best Way to Store Locators: http://stackoverflow.com/questions/28091455/best-way-to-store-locators

切换不同的topaccount 要确保页面的account tree的drop downlist 也要同时刷新 所以要验证account drop down tree的数据
方式1: 获取drop down 下面的items 循环比较
方式1: 获取dropdown item 父元素 比较父元素的innerText

1. How to Resolve Stale Element Reference Exception?

First of all lets be clear about what a WebElement is: A WebElement is a reference to an element in the DOM.
A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated.
When this happens the reference to the element in the DOM that you previously had becomes stale and you are no longer able to use this reference to interact with the element in the DOM. When this happens you will need to refresh your reference, or in real world terms find the element again.
Sometimes you see the exception when you build your testing while debug not, that because when you debug, the client is not as fast as if you just run a unit test or a maven build. This means in debug mode the client has more time to prepare the element, but if the build is running the same code he is much faster and the WebElement your looking for is might not visible in the DOM of the Page.

Sleep for some time to wait the element attached to DOM before interact with them

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)

An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator)

Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

2.输入框输入字后需要点击一下屏幕其他地方触发数据校验 怎么实现?
  比如我在一个输入框书写一个名字后 需要点击屏幕空白地区 来确认我输入的没问题
  需要这样操作的话,可以不一定非得要点击空白区域,因为空白区域对应selenium来说没法操作。可以点击一个没有连接的静态图片或者文字,也是一样的效果

3. driver.manage().deleteAllCookies();
  在webdriver 启动浏览器的时候,它会启动一个干净的,也就是说没有插件,没有cookies, 没有任务的浏览器,所以在刚启动的时候如果不需要测试浏览器,也没有必要调用deleteAllCookies()方法。Tested with IE, Chrome, FF.

4. Input element, readonly and no value attribute

5. 在指定的当前节点下搜索满足要求的节点

在通过selenium使用xpath选择节点的时候,可能会遇到这么一种情况:在指定的当前节点下搜索满足要求的节点

node = driver.find_element_by_xpath("//div[@class='WB_cardwrap S_bg2 clearfix']")
BZNC = node.find_element_by_xpath("//div[@class='feed_content wbcon']/a[@class='W_texta W_fb']").text
BZZY = node.find_element_by_xpath("//div[@class='feed_content wbcon']/a[@class='W_texta W_fb']").get_attribute("href")

以上代码有什么错误吗?貌似没有,一切都很完美。
先拿到node节点,然后在node节点的子节点中搜索满足条件的节点并取出text及属性。
but!运行的结果却是把整个html中所有满足条件的节点都找出来了,而并非是node节点下的!!!仔细想一想,"//div"貌似就是搜索整个html下的div,即使是node下的find_element_by_xpath方法!
所以,只需要在”//”前面加上表示当前路径的"."既可,也就是node.find_element_by_xpath(“.//div”)

/**
* Find the first {@link WebElement} using the given method. See the note in
* {@link #findElements(By)} about finding via XPath.
* This method is affected by the 'implicit wait' times in force at the time of execution.
* The findElement(..) invocation will return a matching row, or try again repeatedly until
* the configured timeout is reached.

* findElement should not be used to look for non-present elements, use {@link #findElements(By)}
* and assert zero length response instead.*

* @param by The locating mechanism
* @return The first matching element on the current context.
* @throws NoSuchElementException If no matching elements are found
* @see org.openqa.selenium.By
* @see org.openqa.selenium.WebDriver.Timeouts
*/

WebElement findElement(By by);

public WebElement getElement(WebElement ancestor, UIElement uiElement){
  WebElement element = null;
  element = ancestor.findElement(uiElement.getBy());
  return element;
}

WebElement deleteWE = viewWE.findElement(By.xpath("./../span[contains(@class, 'glyphicon-minus-sign')]"));

6. Element is not clickable at point (411, 675). Other element would receive the click: ..." 
This is caused by following 3 types: 
1.The element is not visible to click. 
Use Actions or JavascriptExecutor for making it to click.

By Actions:

WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver); actions.moveToElement(element).click().perform();
By JavascriptExecutor:
JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("scroll(250, 0)"); // if the element is on top. jse.executeScript("scroll(0, 250)"); // if the element is on bottom.
or
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView()", Webelement);
Then click on the element.
2.The page is getting refreshed before it is clicking the element. 
For this, make the page to wait for few seconds.
3. The element is clickable but there is a spinner/overlay on top of it
The below code will wait until the overlay disppears
By loadingImage = By.id("loading image ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
Then click on the element.

Element.scrollIntoViewIfNeeded(boolean opt_center) // recommend false
The Element.scrollIntoViewIfNeeded() method scrolls the current element into the visible area of the browser window if it's not already within the visible area of the browser window. If the element is already within the visible area of the browser window, then no scrolling takes place. This method is a proprietary variation of the standard Element.scrollIntoView() method.
Parameters
opt_center
Is an optional Boolean value with a default value of true:
If true, the element will be aligned so it is centered within the visible area of the scrollable ancestor.
If false, the element will be aligned to the nearest edge of the visible area of the scrollable ancestor. Depending on which edge of the visible area is closest to the element, either the top of the element will be aligned to the top edge of the visible area, or the bottom edge of the element will be aligned to the bottom edge of the visible area.

element.scrollIntoView(); // Equivalent to element.scrollIntoView(true)
element.scrollIntoView(alignToTop); // Boolean arguments
element.scrollIntoView(scrollIntoViewOptions); // Object argument
Is a Boolean value:
If true, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. This is the default value.
If false, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor.

Selenium 遇到的问题的更多相关文章

  1. Python爬虫小白入门(四)PhatomJS+Selenium第一篇

    一.前言 在上一篇博文中,我们的爬虫面临着一个问题,在爬取Unsplash网站的时候,由于网站是下拉刷新,并没有分页.所以不能够通过页码获取页面的url来分别发送网络请求.我也尝试了其他方式,比如下拉 ...

  2. Selenium的PO模式(Page Object Model)[python版]

     Page Object Model 简称POM  普通的测试用例代码: .... #测试用例 def test_login_mail(self): driver = self.driver driv ...

  3. selenium元素定位篇

    Selenium webdriver是完全模拟用户在对浏览器进行操作,所有用户都是在页面进行的单击.双击.输入.滚动等操作,而webdriver也是一样,所以需要我们指定元素让webdriver进行单 ...

  4. selenium自动化基础知识

    什么是自动化测试? 自动化测试分为:功能自动化和性能自动化 功能自动化即使用计算机通过编码的方式来替代手工测试,完成一些重复性比较高的测试,解放测试人员的测试压力.同时,如果系统有不份模块更改后,只要 ...

  5. 幼儿园的 selenium

    from selenium import webdriver     *固定开头     b=webdriver.Firefox()              *打开火狐浏览器    browser. ...

  6. 使用selenium编写脚本常见问题(一)

    前提:我用selenium IDE录制脚本,我用java写的脚本,如果大家想看的清楚明白推荐java/Junit4/Webdriver 我用的是java/TestNG/remote control 1 ...

  7. 关于selenium RC的脚本开发

    第一.需要录制脚本,找个我也不说了.就是在firefox下下载一个selenium-IDE并且安装. 第二.在工具里找到selenium-IDE点击运行. 第三.默认是红色按钮点击状态的,接下来随便你 ...

  8. 基于python的selenium自动化测试环境安装

    1. Python2安装 官方网站:https://www.python.org/downloads/ (python3或新版本已经默认集成了pip包和path,安装的时候打勾就行,可以直接跳过下面第 ...

  9. Selenium+python 配置

    1. 安装python, www.python.org. 下载最新的python,应该是32位的.注意配置环境变量. 2. 安装PIP(pip是一个以Python计算机程序语言写成的软件包管理系统). ...

  10. selenium 使用action进行鼠标,键盘操作

    <!--test.html--> <html> <head> <title>Set Timeout</title> <script&g ...

随机推荐

  1. c++find函数用法

    头文件 #include <algorithm> 函数实现 template<class InputIterator, class T> InputIterator find ...

  2. 【现代程序设计】homework-10

    作业地址:http://www.cnblogs.com/xinz/p/3441537.html 进行中...

  3. ML 03、机器学习的三要素

    机器学习算法原理.实现与实践——机器学习的三要素 1 模型 在监督学习中,模型就是所要学习的条件概率分布或决策函数.模型的假设空间包含所有可能的条件概率分布或决策函数.例如,假设决策函数是输入变量的线 ...

  4. Gym 100463A Crossings 逆序对

    Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...

  5. hdu 1290

    http://www.cnblogs.com/songacm/p/3537419.html 引用自这篇博客,真·大神

  6. 编译x264 for ios

    Tested with: x264-snapshot-20140914-2245  我用的是x264-snapshot-20150813-2245.tar.bz2 Xcode 7 依赖gas-prep ...

  7. 绑定GoDaddy域名到OpenShift应用

    一.申请GoDaddy域名 二.托管OpenShift应用 三.绑定www.mydomain.com 四.重定向mydomin.com到www.mydomain.com 五.It's go time ...

  8. 贪心 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx, 接下来mx次循环,若是0,输出0:若是1,输出1,s[j]--: 注意:之前的0的要忽略 */ #inc ...

  9. LightOJ1057 Collecting Gold(状压DP)

    这道题可以想到几点: 整个行程可以看作一次次的行走,每次行走都是用最短的路程从某一非空点到达另外一非空点: 两点间最少的步数是二者x和y坐标差的最大值: 返回原点这个过程,肯定是取完最后一个黄金后直接 ...

  10. BZOJ1035 : [ZJOI2008]Risk

    首先要将这个图连通,方法是通过扫描线+set求出每个连通块最高的点上方的第一条边,然后向交点连边. 然后把边拆成两条双向边,每次找到一条没走过的边,找到极角排序后它的反向边的后继,直到回到这条边.根据 ...