问题:用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. 关于python使用threadpool中的函数单个参数和多个参数用法举例

    1.对单个元素的函数使用线程池: # encoding:utf-8 __author__='xijun.gong' import threadpool def func(name): print 'h ...

  2. Python 操作 GA API 指南

    因为需要写一个 Blog Feature 的缘故,所以接触了下 GA 的 Python API,发现 G 家的 API 不是那么直观,比较绕,但是,在使用过程中发现其实 G 家的 API 设计挺有意思 ...

  3. 细说log4j

    可能做过java项目的基本上都是用过log4j,它是用来做java日志的.比如我们做一个项目分为很多的模块,那我们怎么想要知道它什么时候启动了,这时候我们可以使用log4j标记某某模块启动了. 努力的 ...

  4. bzoj 3065: 带插入区间K小值(分块)

    Description 从前有n只跳蚤排成一行做早操,每只跳蚤都有自己的一个弹跳力a[i].跳蚤国王看着这些跳蚤国欣欣向荣的情景,感到非常高兴.这时跳蚤国王决定理性愉悦一下,查询区间k小值.他每次向它 ...

  5. Codeforces 791A Bear and Big Brother(暴力枚举,模拟)

    A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:stand ...

  6. [FZU1977] Pandora adventure

    来学插头DP了= = GDKOI前觉得不会考数位DP,GDOI前觉得插头DP用不上.. 结果令人伤感>_< 这题并不用增加状态.. 只要在形成环的时候,让形成环的位置在最后一个必走点之后, ...

  7. MySQL数据库全备

    #function:MYSQL自动全备 #version:1.0.0 #author:wangyanlin #date:2017/08/03 #---------------------------- ...

  8. c语言变量类型联想

    int float char *(指针) 已经定义:单个变量 单个相同类型在内存中顺序存放:数组 不同单个类型在内存中顺序存放:结构体 不同类型在内存中自由存放:链表 其中结构体与链表类型需运用时提前 ...

  9. 解决不同操作系统下git换行符一致性问题

    一.不同操系统下的换行符CR回车 LF换行Windows/Dos CRLF \r\nLinux/Unix LF \nMacOS CR \r二.解决方法 打卡git bash,设置core.autocr ...

  10. 立即掌握SSM框架的要诀

    ssm框架的总结: 1. 首先是POM.xml 文件的配置,他的作用主要是添加依懒的关系和自动下载相关的包. 2.对jdbc.properties进行配置 ,作用就是连接你的数据库的配置. 3.对接着 ...