### 问题

捕捉页面上js error

### 解决办法

从Selenium webdriver log 中解析

  1. # -*- coding:utf8 -*-
  2.  
  3. import unittest
  4. from selenium import webdriver
  5. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  6.  
  7. class CaptureJSError(unittest.TestCase):
  8.  
  9. @classmethod
  10. def setUp(self):
  11. self.driver = webdriver.Remote('http://yourseleniumgrid:4444/wd/hub',
  12. desired_capabilities=DesiredCapabilities.FIREFOX)
  13. def test_search_in_python_org(self):
  14. driver = self.driver
  15. driver.get("http://foopagewitherr:80")
  16. logs = driver.get_log('browser')
  17. for log in logs:
  18. if log['level'] == 'SEVERE':
  19. print log
  20. # output is {u'timestamp': 1474618002360, u'message': u'TypeError: $(...).ready_ is not a function', u'level': u'SEVERE'}
  21.  
  22. @classmethod
  23. def tearDown(self):
  24. self.driver.close()
  25.  
  26. if __name__ == "__main__":
  27. 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的更多相关文章

  1. java selenium webdriver处理JS操作窗口滚动条

    未经作者允许,禁止转载!!! java selenium webdriver处理JS操作窗口滚动条 java selenium webdriver处理JS操作窗口滚动条 import org.open ...

  2. Python selenium webdriver设置js操作页面滚动条

    js2 = "window.scrollTo(0,0);" #括号中为坐标 当不知道需要的滚动的坐标大小时: weizhi2 = driver.find_element_by_id ...

  3. selenium,webdriver 执行js语句 对象是百度

    代码要多敲 注释要清晰 最后的两种方法,没有实现我想要的结果 有知道的朋友,给我留言吧 #执行js语句 from selenium import webdriver import time #生成浏览 ...

  4. 【Python + Selenium】之JS定位总结

    感谢:小琰子 Python+Selenium 脚本中的一些js的用法汇总: 1.滚动条 driver.set_window_size(500,500) js = "window.scroll ...

  5. 解决Ruby在IE11中报Unable to get browser (Selenium::WebDriver::Error::NoSuchWindowError)的错误

    转载地址:http://www.tuicool.com/articles/BRnqeu2 I was updating the browser WebDrivers for    Seleno    ...

  6. 一行js代码识别Selenium+Webdriver及其应对方案

    有不少朋友在开发爬虫的过程中喜欢使用Selenium + Chromedriver,以为这样就能做到不被网站的反爬虫机制发现. 先不说淘宝这种基于用户行为的反爬虫策略,仅仅是一个普通的小网站,使用一行 ...

  7. Selenium Webdriver——JS处理rich text(富文本框)

    126邮件正文邮件的rich text 先让selenium切换到iframe中 driver.switchTo().frame(driver.findElement(By.className(&qu ...

  8. selenium webdriver——JS对Input执行输入

    直接设置value属性, 此方法主要应对输入框自动补全以及readonly属性的element,sendkeys不稳定 比如: Demo:用JS输入 import org.openqa.seleniu ...

  9. selenium webdriver——JS滚动到指定位置

    1.DOM滚动方法 1.scrollIntoView(alignWithTop)  滚动浏览器窗口或容器元素,以便在当前视窗的可见范围看见当前元素.如果alignWithTop为true,或者省略它, ...

随机推荐

  1. centos 7 下安装numpy、scipy等python包

    本文适用于刚入门的小白,欢迎大牛们批评指正. 因为要开始数据分析,而python又不像R和matlab那么简洁.需要安装的包很多~ 网上找了好多牛人博客,想在centos7下安装numpy,scipy ...

  2. asp.net文件下载文件另存为

    这是一个困惑已久的问题…… 首先,用<a>标签的href打开浏览器能解读的文件(如txt,jpg,pdf等),会自动打开,无法做到弹出另存为的效果. 其次,网上搜索了各种JS解决办法,包括 ...

  3. 横向滑动的GridView

    思路: GridView行数设置为一行,外面套一个HorizontalScrollView,代码中设置GridView宽度 xml代码 <HorizontalScrollView android ...

  4. JDBC操作步骤及数据库连接操作

    http://blog.csdn.net/joywy/article/details/7731305

  5. s验证数据库中字段值是否重复

    daoImpl: public String isVipCode(String vipcode) { String sql = "from FfzjUserEntity where vip_ ...

  6. HTML编辑器

    终于有时间静下来总结一下最近的工作. 第一个就是html编辑器: 首先是编辑器的选择,之前用的是ewebeditor,功能很强大,出于粘贴word内容得安装插件的原因,暂时放弃. ewebeditor ...

  7. js/jquery获取文本框的值与改变文本框的值

    我们就用它来学习获取文本框的值及改变文本框的值. 代码如下 复制代码 <script>function get1(){ document.getElementById("txtb ...

  8. WebDriver 常见Exception处理

    1. org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code&quo ...

  9. 位置指纹(LF)定位技术简介-室内定位

        信号的多径传播对环境具有依赖性,呈现出非常强的特殊性.对于每个位置而言,该位置上信道的多径结构是惟一的,终端发射的无线电渡经过反射和折射,产生与周围环境密切相关的特定模式的多径信号,这样的多径 ...

  10. ThinkPHP_基础(1)目录结构

    (说明:文中的颜色一一对应) 目录结构 www WEB部署目录(或者子目录) ├─index.php 入口文件 ├─README.md README文件 ├─composer.json Compose ...