问题:用selenium+phantomjs 模拟登陆,网页用JavaScript的alert(“登陆成功”)弹出框,但是用switch_to_alert().accept()报错,不可执行命令。

目标代码:<script language="javascript">alert('********************');</script>

显示错误:

File "sy.py", line 112, in <module>
Pop123= Pop_up.text
File "C:\Python27\lib\site-packages\selenium\webdriver\common\alert.py", line 69, in text
return self.driver.execute(Command.GET_ALERT_TEXT)["value"]
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Invalid Command Method - {"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:59198","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"GET","url":"/alert_text","urlParsed":{"anchor":"","query":"","file":"alert_text","directory":"/","path":"/alert_text","relative":"/alert_text","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/alert_text","queryKey":{},"chunks":["alert_text"]},"urlOriginal":"/session/95d315d0-ce94-11e7-8d72-c1b9396af0ea/alert_text"}

搜到的解决方案:

   phantomjs是没有界面的,无法j解析动态的JS,所以对alert也是无法直接弹出的,故phantomjs以该函数回调在page在执行过程中的alert事件。

  python没有对应phentomjs特殊的库,所以需要调用JS。

  python selenium官方已不再对phentomjs提供支持。现在主打火狐浏览器 和 谷歌浏览器 请尽量更换

一 、python调用Js

  r = driver.execute_script("return newsJason")

  print r

二、Js里面的方法          时间较忙未进行测试对错

  page.onAlert = function(msg) {}

  driver.execute_script("window.confirm = function(msg) { return true; }");

        

python selenium+phantomjs alert()弹窗报错的更多相关文章

  1. JavaScript实现弹窗报错

    JavaScript实现弹窗报错 1.具体错误如下 SCRIPT 5022:cannot call methods on dialog prior to initialization; attempt ...

  2. Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence

    Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal mul ...

  3. python安装包的时候报错

    python安装包的时候报错 今天兴致勃勃的安装了一个paramiko包,过程很顺利,但是到结尾的时候报错,这就让人不爽了. 所以呢,需要安装一个名为python-dev的软件包. 该软件包包括头文件 ...

  4. python selenium phantomjs 报错

    报错: webdriver.PhantomJS() raise exception_class(value)selenium.common.exceptions.WebDriverException: ...

  5. python + selenium + PhantomJS 获取腾讯应用宝APP评论

    PhantomJS PhantomJS 是一个基于WebKit的服务器端JavaScript API,它无需浏览器的支持即可实现对Web的支持,且原生支持各种Web标准,如DOM 处理.JavaScr ...

  6. Python+Selenium学习--alert/confirm/prompt 处理

    场景 webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confi ...

  7. python selenium+phantomJS自动化测试环境

    0x00配置phantomJS 1. 在windows平台下 此种方法是弹浏览器进行自动化测试的. 1.下载谷歌的驱动 https://chromedriver.storage.googleapis. ...

  8. selenium的安装、报错和解决

      selenium是的作用是模拟点击浏览器上的按钮,配合一个无头浏览器就可以快速解决一些前端需要加解密的功能. 第一步pip install selenium安装的第一步就是用pip把模块下载回来. ...

  9. Selenium click不生效 报错selenium.common.exceptions.InvalidArgumentException

    记录在使用selenium过程中踩的坑------ 在使用selenium时,用click点击网站弹出的文件上传框的"上传文件"按钮不生效,报错selenium.common.ex ...

随机推荐

  1. LVS集群之NAT模式实例(3)

    LVS集群NAT模式实例 1. 实验拓扑图 DS 必须有两块网卡,需要在上面做NAT. 2. 实验环境 3台CentOS6.4 64bit的服务器. 类型 IP DR eth0:10.20.73.20 ...

  2. javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

    前言 今天一个朋友让我帮他做一下tomcat的https配置,中间遇到了标题中这个错误,因此记录了一下过程,服务器.域名.证书.tomcat都已经准备好,就是需要配置一下即可,用的是阿里云的证书服务, ...

  3. 存储库-MongoDB简单的操作

    简介: MongoDB是一款强大.灵活.且易于扩展的通用型数据库 1.易用性 MongoDB是一个面向文档的数据库,而不是关系型的数据库: 不采用关系型主要是为了可扩展性 2.易扩展性 存储在Mong ...

  4. 学习笔记-echarts点击数据添加跳转链接

    原链接:http://echarts.baidu.com/demo.html#pie-rich-text 这个一段官方提供的实例. var weatherIcons = { 'Sunny': './d ...

  5. 【Java学习笔记之六】java三种循环(for,while,do......while)的使用方法及区别

    第一种:for循环 循环结构for语句的格式:       for(初始化表达式;条件表达式;循环后的操作表达式) { 循环体;    } eg: class Dome_For2{ public st ...

  6. Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】

    J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...

  7. POJ3258-River Hopscotch-二分

    这个题就是排排坐,二分就可以了... River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1325 ...

  8. init和plus(编码中遇到问题就看这里)

    转自:http://ask.dcloud.net.cn/article/165 编码中遇到问题就看这里: http://uikoo9.com/book/chapterDetail/4 plus初始化原 ...

  9. Spring的IOC分析(一)

    我们学习Spring之前需要对23种java的设计模式的9种有一定的理解,设计模式为了解耦,Spring也是在解耦的方向上设计的,所以设计模式要理解一下,它当中用到了很多. 单例模式(写法很多钟,7种 ...

  10. [国嵌攻略][165][usb下载线驱动设计]

    查看USB设备的生产商ID和设备ID 示例: lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 生产商ID是1d ...