如何用selenium webdriver 捕获js error
### 问题
捕捉页面上js error
### 解决办法
从Selenium webdriver log 中解析
# -*- coding:utf8 -*- import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities class CaptureJSError(unittest.TestCase): @classmethod
def setUp(self):
self.driver = webdriver.Remote('http://yourseleniumgrid:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://foopagewitherr:80")
logs = driver.get_log('browser')
for log in logs:
if log['level'] == 'SEVERE':
print log
# output is {u'timestamp': 1474618002360, u'message': u'TypeError: $(...).ready_ is not a function', u'level': u'SEVERE'} @classmethod
def tearDown(self):
self.driver.close() if __name__ == "__main__":
unittest.main()
Note:
这里的webdriver是由Selenium Grid提供的,本地webdriver 应该也是可以的
### 引用
https://www.3pillarglobal.com/insights/how-to-capture-javascript-errors-from-your-web-application
如何用selenium webdriver 捕获js error的更多相关文章
- java selenium webdriver处理JS操作窗口滚动条
未经作者允许,禁止转载!!! java selenium webdriver处理JS操作窗口滚动条 java selenium webdriver处理JS操作窗口滚动条 import org.open ...
- Python selenium webdriver设置js操作页面滚动条
js2 = "window.scrollTo(0,0);" #括号中为坐标 当不知道需要的滚动的坐标大小时: weizhi2 = driver.find_element_by_id ...
- selenium,webdriver 执行js语句 对象是百度
代码要多敲 注释要清晰 最后的两种方法,没有实现我想要的结果 有知道的朋友,给我留言吧 #执行js语句 from selenium import webdriver import time #生成浏览 ...
- 【Python + Selenium】之JS定位总结
感谢:小琰子 Python+Selenium 脚本中的一些js的用法汇总: 1.滚动条 driver.set_window_size(500,500) js = "window.scroll ...
- 解决Ruby在IE11中报Unable to get browser (Selenium::WebDriver::Error::NoSuchWindowError)的错误
转载地址:http://www.tuicool.com/articles/BRnqeu2 I was updating the browser WebDrivers for Seleno ...
- 一行js代码识别Selenium+Webdriver及其应对方案
有不少朋友在开发爬虫的过程中喜欢使用Selenium + Chromedriver,以为这样就能做到不被网站的反爬虫机制发现. 先不说淘宝这种基于用户行为的反爬虫策略,仅仅是一个普通的小网站,使用一行 ...
- Selenium Webdriver——JS处理rich text(富文本框)
126邮件正文邮件的rich text 先让selenium切换到iframe中 driver.switchTo().frame(driver.findElement(By.className(&qu ...
- selenium webdriver——JS对Input执行输入
直接设置value属性, 此方法主要应对输入框自动补全以及readonly属性的element,sendkeys不稳定 比如: Demo:用JS输入 import org.openqa.seleniu ...
- selenium webdriver——JS滚动到指定位置
1.DOM滚动方法 1.scrollIntoView(alignWithTop) 滚动浏览器窗口或容器元素,以便在当前视窗的可见范围看见当前元素.如果alignWithTop为true,或者省略它, ...
随机推荐
- web前端基础篇⑨
1.web端.app端 目前实现响应式布局,主要用以下两种方式.CSS原生代码响应式布局 @media screen.bootstrap移动设备优先.自带框架. 兼容性 用原生代码的话 根据不同的屏幕 ...
- 第十章 嵌入式Linux的调试技术
对调试工具进行简介.Linux中提供了一类工具,通过这些工具可以逐行跟踪程序的代码,用于测试用户空间程序的gdb.gdbserver和调试内核空间程序的kgdb. 用gdb调试用户空间程序:gdb可跟 ...
- android 帧动画的实现及图片过多时OOM解决方案(一)
一,animation_list.xml中静态配置帧动画的顺序,如下: <?xml version="1.0" encoding="utf-8"?> ...
- ionic cordova 热更新(引用自www.zyyapp.com/post/116.html)
上篇文章cordova 把html打包成安卓应用 http://www.zyyapp.com/post/115.html cordova 热更新是一个大坑,我看了一天一夜才明白.网上的教程都没说到重点 ...
- MFC之TreeCtrl控件使用经验总结
树形控件可以用于树形的结构,其中有一个根接点(Root)然后下面有许多子结点,而每个子结点上有允许有一个或多个或没有子结点.MFC中使用CTreeCtrl类来封装树形控件的各种操作.通过调用BOOL ...
- 2016 - 1 - 25 CSS初步 (二)
1.The customising link We can change the link's style when we move our pointer on the link like that ...
- 一次偶然的Java内存溢出引发的思考
据说一次SQL查询返回太多数据,会引起服务器内存溢出. 不过,我现在碰到的情况是,调用一个Postgresql 存储过程,很复杂,那么在其中有很多raise notice这样的调试语句,如果碰巧有个死 ...
- Cookies的作用
Cookie,有时也用其复数形式Cookies,指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密).Cookies就是服务器暂存放在你的电脑里的资料(.tx ...
- 在Visual Studio中使用Git命令提示符
VS2015自带了Git插件,但有时候我觉得Git控制台命令更方便些. VS中本身不能把Git Bush作为浮动窗集成进来,但我们可以通过Power Shell来使用Git命令. ---------- ...
- SIP模块版本错误问题:the sip module implements API v??? but XXX module requires API v???
系统安装了python 2.7,继续安装PyQt4,于是依次下载sip.pyqt4源码进行安装.用以下代码测试: import PyQt4.QtGui 显示出错.错误信息:the sip module ...