
Selenium 学习笔记
尤鸟倦
我与我周旋久,宁作我
展开
-
How to use “print“ in behave
First, before anything else:You are entering and comparing strings and not numbers in your steps.Per default, behave captures stdout. This captured output is only shown if a failure occurs.This behaviour is sufficient for most cases.If you do not like原创 2020-10-14 09:12:54 · 506 阅读 · 0 评论 -
Python自动化轮播控件中元素not clickable报错处理
##问题:想要进行依次点击专题栏中的链接. 下方是一个轮播条.在点击A中第二篇文章时, 报错 . is not clickable at point (481, 343). Other element would receive the click:##解决方案:判断为轮播抢走了浏览器焦点. 导致点击失败. 获取一个固定的元素, 这里获取了专题栏的title元素. 在每次点击文章前, 先执行下点击专题栏标题操作, 抢回焦点. 问题解决....原创 2020-10-09 15:29:48 · 4205 阅读 · 0 评论 -
Edge, IE11修改cookie
Edge, IE11修改cookiechrome可以直接在控制台 application中 直接修改cookieedge和ie11 不能直接修改, 可以通过在控制台运行JSdocument.cookie = "cookie_name=cookie_value";...原创 2019-10-15 18:06:25 · 5715 阅读 · 0 评论 -
Selenium学习16--ExcelUtil
//本类主要实现扩展名为.xlsx的excel文件操作public class ExcelUtil{ private static XSSFSheet ExcelWSheet; private static XSSFWorkbook ExcelWBook; private static XSSFCell Cell; //设定要操作的excel的文件路径和excel文件中原创 2016-10-31 16:43:17 · 555 阅读 · 0 评论 -
Selenium学习笔记2--定位元素
查找条件对象By需要对特定页面元素进行操作时,必须先获取到元素对象, 根据HTML的不同条件进行定位.Id(idToFind)<input autocomplete="off" maxlength="255" value="" class="s_ipt" name="wd" id="kw">这个是百度的搜索框, 可以通过ID来定位.navigate.to("http://www.baidu.com"原创 2016-09-05 22:14:46 · 462 阅读 · 0 评论 -
Selenium学习17--testng
TestNG官方文档testng DTD<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >原创 2017-06-29 21:44:22 · 298 阅读 · 0 评论 -
Selenium学习笔记18-问题汇总
1.启动chrome有类似”disable-extensions”或者”wrong context” 提示chrome webdriver 版本过低,更新版本针对extensions也可以尝试代码:ChromeOptions options = new ChromeOptions();options.addArguments("chrome.switches","--disable-exten原创 2017-06-30 09:33:22 · 294 阅读 · 0 评论 -
Selenium学习笔记19-操作控件设置高亮
所谓控件高亮,其实就是JS设置背景色//封装高亮控件方法public void highlighElement(WebElement element){ JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("argments[0].setAttribute('style',argments[1]转载 2017-07-04 16:18:49 · 379 阅读 · 0 评论 -
Selenium学习笔记20-Table工具类
Table Classpublic class Table { private WebElement table; public Table(WebElement table) { super(); this.table = table; } public WebElement getTable() { return tabl原创 2017-07-04 19:22:40 · 343 阅读 · 0 评论 -
Selenium学习笔记21_CSS Selector
翻译自: 英文原文链接The following table summarizes the Selector syntax: 模式 含义 描述 CSS Level * any element universal selector 2 E an element of type E Type selector 1 E[foo] an E elemen转载 2017-10-23 15:21:16 · 335 阅读 · 0 评论 -
Css Selector
Multiple attribute selectors can be used to represent several attributes of an element, or several conditions on the same attribute. Here, the selector represents a span element whose hello attribute ...转载 2019-07-22 15:13:15 · 220 阅读 · 0 评论 -
Selenium学习15--WaitUtil
线程休眠和显示等待查找页面元素是否存在的工具类public class WaitUtil{ //用于测试执行过程中暂停程序执行的休眠方法 public static void sleep(long millisecond){ try{ Thread.sleep(millisecond); }catch(Exception e){原创 2016-10-31 14:01:19 · 1293 阅读 · 0 评论 -
Selenium学习14--KeyBoardUtil
封装键盘操作的工具类public class KeyBoardUtil{ //press Tab key public static void pressTabKey(){ Robot robot = null; try{ robot = new Robot(); }catch(Exception原创 2016-10-31 13:55:40 · 554 阅读 · 0 评论 -
Selenium学习8--截图,拖拽页面元素,键盘操作,鼠标右键,悬停,鼠标双击
1. 当前窗口截图 @Test public void captureScreenInCurrentWindow(){ driver.get("http:www.sogou.com"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try{原创 2016-09-14 18:27:47 · 4639 阅读 · 0 评论 -
Selenium学习5--浏览器多窗口和TimesOut
新窗口弹出后, 可以通过他的标识符切换到此窗口,在对窗口的元素进行操作WebDriver mainWindow = new FirefoxDriver();Navigation navigation = mainWindow.navigate();navigation.to("http://www.baidu.com");WebElemen bnInMainWindow = mainWindo原创 2016-09-11 22:44:35 · 808 阅读 · 0 评论 -
Selenium学习笔记1--选择浏览器,定位网页
选择浏览器public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("真武七截剑"); //火狐浏览器 //System.setProperty("webdriver.firefox.bin", "C:\\原创 2016-09-05 20:16:43 · 919 阅读 · 0 评论 -
Selenium学习笔记3--元素操作
上一篇提到了如果获取页面元素Selenium学习笔记2–获取页面元素,获取元素之后当然就是对元素进行操作.Click()点击操作WebElement baiduLogin = driver.findElement(By.LinkText("登录"));baiduLogin.click(); 注意: Selenium2 中checkbox的勾选也是click操作SendKeysSendKeys()方原创 2016-09-06 11:27:43 · 525 阅读 · 0 评论 -
Selenium学习7--结束测试
结束测试后, 有两种方法处理, close()关闭当前webDriver所在的窗口, quit()方法关闭所有相关窗口WebDriver mainWindow = new FirefoxDriver();Navigation navigation = mainWindow.navigate();navigation.to("http://www.baidu.com");WebElemen bn原创 2016-09-11 23:12:33 · 732 阅读 · 0 评论 -
Selenium学习9--显示等待,判断页面元素是否存在
html代码如下: <html lang="en"> <head> <title>your favorite fruits</title> </head> <body> <p>select ur perfer fruit</p> <br> <select name='fruit'> <option id='peach' value='taozi'>pe原创 2016-09-15 16:58:34 · 32098 阅读 · 0 评论 -
Selenium学习10--Frame操作
页面html代码如下:<!doctype html><html lang="en"> <head> <title>frameset page title</title> </head><frameset cols = "25%,50%,25%"> <frame id="leftframe" src ="frame_left.html"/> <frame id="middl原创 2016-09-15 20:58:24 · 477 阅读 · 0 评论 -
Selenium学习笔记4--获取页面元素内容
getTitle()获取当前页面标题String title = driver.getTitle();getCurrentUrl()String url = driver.getCurrentUrl();getText()用户获取某个元素的文本值,比如链接,纯文本等isSelected(): 返回boolean用于获取checkbox勾选情况getTagName()获取元素标签名称WebElemen原创 2016-09-06 14:03:51 · 8215 阅读 · 0 评论 -
Selenium学习11--精确比较网页截图图片
@Test public void testImage(){ driver.get("http://www.sogou.com"); File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try{ Thread.sleep(3000);原创 2016-09-20 16:42:13 · 2325 阅读 · 0 评论 -
Selenium学习12--数据驱动csv
@DataProvider(name="testData") public static Object[][] words() throws Exception{ return getTestData("d:\\textCSV.csv"); }解析csv文件public static Object[][] getTestData(String fileName) throws E原创 2016-09-20 23:36:27 · 1405 阅读 · 0 评论 -
Selenium学习13--表格定位
测试网页html代码如下:<html lang="en"> <head> </head> <body> <table width="400" border="1" id="table"> <tr> <td align="left">消费项目</td> <td align="right">一月</td> <td align="right">二月</td> </原创 2016-10-29 13:41:52 · 3322 阅读 · 0 评论 -
Selenium学习笔记6--EventFiringWebDriver网页事件监听
可以满足一下需求 1.执行打开网页的操作室, 需要分别记录打开前和之后的URL地址. 2.在查找某个页面元素时候, 查找之前和之后都需要记录查找条件 3.在对页面进行单机操作室, 单击前需要记录元素的查找条件, 单机后记录URL地址 4.在对页面元素的值进行更改, 需要分别记录更改前的值和更改后的值 5.在发生异常的时候, 需要进行截图, 将截图文件保存在D:\ , 用当前日期命名文件pu原创 2016-09-11 23:06:26 · 7521 阅读 · 0 评论