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 ...
随机推荐
- MATLAB信号与系统分析(二)——离散时间信号与系统的时域分析
一.离散信号的表示 1.一个离散信号需要用两个向量来表示: (1)离散信号的幅值 (2)离散信号的位置信息 2.用MATLAB实现离散信号的可视化 (1)不能利用符号运算来表示 (2)绘制离散信号一般 ...
- SQL2005备份数据库到远程服务器中
--打开高级设置EXEC sp_configure 'show advanced options', 1RECONFIGURE--打开xp_cmdshell扩展存储过程EXEC sp_configur ...
- php生成二维码的插件phpqrcode
参考网址: http://www.thinkphp.cn/topic/7749.html http://blog.csdn.net/stxyc/article/details/44650971 php ...
- Android Studio 1.0首次安装遇到的问题,无法下载SDK
相信,在安装Android Studio的过程中会遇到很多问题,特别是第一次启动下载不了sdk.郁闷了吧. 可以去官网下载,也可以点击这里下载Android Studio和sdk. 一.不下载SDK启 ...
- Web测试Selenium:如何选取元素
Web测试工具Selenium:如何选取元素 2009-02-17 23:23 by 敏捷的水, 5372 阅读, 22 评论, 收藏, 编辑 selenium是一个非常棒的Web测试工具,他对Aja ...
- 2016 Multi-University Training Contest 8
solved 4/11 2016 Multi-University Training Contest 8 贪心 1001 Ball(BH) 代码: #include <bits/stdc++.h ...
- CGOS461 [网络流24题] 餐巾(最小费用最大流)
题目这么说的: 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,…,N).餐厅可以从三种途径获得餐巾. 购买新的餐巾,每块需p分: 把用过的餐巾送到快洗部,洗一块需m天,费用需f分(f< ...
- Android view 的事件分发机制
1 事件的传递顺序是 Activity -> Window -> 顶层View touch 事件产生后,最先由 activity 的 dispatchTouchEvent 处理 /** * ...
- Rain on your Parade
Rain on your Parade Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 655350/165535 K (Java/Ot ...
- [Leetcode] Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...