Selenium 遇到的问题
鼠标刚好位于下拉列表上面 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. 在指定的当前节点下搜索满足要求的节点
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')]"));
By Actions:
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 遇到的问题的更多相关文章
- Python爬虫小白入门(四)PhatomJS+Selenium第一篇
一.前言 在上一篇博文中,我们的爬虫面临着一个问题,在爬取Unsplash网站的时候,由于网站是下拉刷新,并没有分页.所以不能够通过页码获取页面的url来分别发送网络请求.我也尝试了其他方式,比如下拉 ...
- Selenium的PO模式(Page Object Model)[python版]
Page Object Model 简称POM 普通的测试用例代码: .... #测试用例 def test_login_mail(self): driver = self.driver driv ...
- selenium元素定位篇
Selenium webdriver是完全模拟用户在对浏览器进行操作,所有用户都是在页面进行的单击.双击.输入.滚动等操作,而webdriver也是一样,所以需要我们指定元素让webdriver进行单 ...
- selenium自动化基础知识
什么是自动化测试? 自动化测试分为:功能自动化和性能自动化 功能自动化即使用计算机通过编码的方式来替代手工测试,完成一些重复性比较高的测试,解放测试人员的测试压力.同时,如果系统有不份模块更改后,只要 ...
- 幼儿园的 selenium
from selenium import webdriver *固定开头 b=webdriver.Firefox() *打开火狐浏览器 browser. ...
- 使用selenium编写脚本常见问题(一)
前提:我用selenium IDE录制脚本,我用java写的脚本,如果大家想看的清楚明白推荐java/Junit4/Webdriver 我用的是java/TestNG/remote control 1 ...
- 关于selenium RC的脚本开发
第一.需要录制脚本,找个我也不说了.就是在firefox下下载一个selenium-IDE并且安装. 第二.在工具里找到selenium-IDE点击运行. 第三.默认是红色按钮点击状态的,接下来随便你 ...
- 基于python的selenium自动化测试环境安装
1. Python2安装 官方网站:https://www.python.org/downloads/ (python3或新版本已经默认集成了pip包和path,安装的时候打勾就行,可以直接跳过下面第 ...
- Selenium+python 配置
1. 安装python, www.python.org. 下载最新的python,应该是32位的.注意配置环境变量. 2. 安装PIP(pip是一个以Python计算机程序语言写成的软件包管理系统). ...
- selenium 使用action进行鼠标,键盘操作
<!--test.html--> <html> <head> <title>Set Timeout</title> <script&g ...
随机推荐
- poj 3252 组合数
主要考察组合数知识,初始化的时候参考公式 首先先推个公式,就是长度为len的Round Numbers的个数. 长度为len,第一位肯定是1了. 那么后面剩下 len-1位 ...
- C调Lua
转自:http://foredoomed.org/blog/2013/12/07/integrate-c-with-lua/ 我们在用C写程序的时候,很多情况下需要用到List,Map等集合,但是C是 ...
- Android系统自带样式(@android:style/) (转)
摘自:http://blog.csdn.net/hongya1109110121/article/details/11985545 在AndroidManifest.xml文件的activity中配置 ...
- loj 1155(最大流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26869 思路:题目还是比较水的,由于点也有容量,则必须拆点,然后跑 ...
- 2016.6.21 PHP与MqSQL交互之图片读取
<td width="265"> <?php mysql_select_db("member"); mysql_query("set ...
- 绑定GoDaddy域名到OpenShift应用
一.申请GoDaddy域名 二.托管OpenShift应用 三.绑定www.mydomain.com 四.重定向mydomin.com到www.mydomain.com 五.It's go time ...
- 简单几何(线段相交) POJ 2653 Pick-up sticks
题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...
- 概率 Gym 100502D Dice Game
题目传送门 /* 题意:两个人各掷两个骰子,给出每个骰子的最小值和最大值,其余值连续分布 问两人投掷,胜利的概率谁大 数据小,用4个for 把所有的可能性都枚举一遍,统计每一次是谁胜利 还有更简单的做 ...
- Piggy-Bank[HDU1114]
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- c/c++ 笔试面试题
#include <iostream> using namespace std; class A { public: void sayHi(){ cout<<"hel ...