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 ...
随机推荐
- Sql server之路 (六)上传服务器图片
原理: 上传图片的名字 插入到数据库里 上传图片的内容(二进制数据) 写到服务器指定的目录下 下次读取图片的时候 从数据库里的指定字段里读取图片文件名 从数据库的指定路径下 拼串成完成的路径 就可以下 ...
- 我对序列化(Serializable)的理解
转自:http://blog.tianya.cn/blogger/post_show.asp?BlogID=764&PostID=3231409 序列化是把一个对象的状态写入一个字节流的过程. ...
- 垂直的SeekBar:VerticalSeekBar
public class VerticalSeekBar extends AbsSeekBar { private Drawable mThumb; public interface OnSeekBa ...
- quick 截屏
MainScene local MainScene = class("MainScene", function() return display.newScene("Ma ...
- wp ApplicationBar
WP7中的菜单栏 一个应用程序的菜单栏的内容是有限的,最多不超过4个,排列顺序是以菜单栏中间为中心,然后从左往右排列. WP7提供了两种类型的菜单栏,一种是全局的菜单栏,也就是说在所有的页面中都会出现 ...
- UOJ#61. 【UR #5】怎样更有力气
大力水手问禅师:“大师,很多事情都需要用很大力气才能完成,而我在吃了菠菜之后力气很大,于是就导致我现在非常依赖菠菜.我很讨厌我的现状,有没有办法少吃点菠菜甚至不吃菠菜却仍很有力气?” 禅师浅笑,答:“ ...
- SecureCrt自动化
Crt自动化 测试 SecureCrt脚本 JS脚本 引言 软件介绍 脚本介绍 引言 在嵌入式公司中,面对大量的网络设备,不论开发同事进行设备开发.测试同事进行大量测试工作还是运维人员进行大量设备 ...
- Mysql 解决left join 数据重复的问题
select p.*,g.roleName,pg.srcType from t_gold_pay_add p left join gRole g on p.roleID=g.roleID left j ...
- 移动端JD首页H5页面
1:理解View :<meta name="viewport" content="width=device-width,initial-scale=1.0" ...
- Nginx在Windows系统和Linux系统下的重启
一.Windows系统下重启nginx 1.杀掉nginx进程 tskill nginx echo 已终止所有ginx进程 2.启动nginx cd f:\nginx- nginx.exe ...