python:selenium测试登录在chrome中闪退
问题描述:使用selenium.webdriver时测试网页,进行自动登录测试总是在登录成功时闪退。使用指定驱动器位置的方式chrome也会闪退
1.正常使用chrome驱动打开一个网页,正常访问
from selenium.webdriver import Chrome
web = Chrome()
web.get("http://www.chaojiying.com/user/login/")

2.在使用selenium测试一个自动登录的程序,测试了很长时间,一直是闪退
chrome版本:版本 99.0.4844.51(正式版本) (64 位)
chromedriver版本:99.0.4844.51
seleniium版本:4.0+
from selenium.webdriver import Chrome
from chaojiying import Chaojiying_Client
from selenium.webdriver.common.by import By
import time web = Chrome()
web.get("http://www.chaojiying.com/user/login/")
time.sleep(5) # Let the user actually see something! # 处理验证码
img = web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png #登录超级鹰 chaojiying = Chaojiying_Client('18312341234', '123456', '912345')
dic = chaojiying.PostPic(img,1902)
verify_code = dic['pic_str'] # 想页面中填入用户名,密码验证码
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys("18312341234")
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys("123456")
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(verify_code) #点击登录
time.sleep(2)
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click() # driver.quit()

3.测试指定浏览器驱动位置
看网上的教程是,没有指定chromedrive.exe的环境变量,或者chrome的内核版本跟chromedrive版本不一致,两种方式都进行了重试,然后在重装,仍然没用,这里是指定chromedrive.exe的代码部分
from selenium import webdriver
from selenium.webdriver.firefox.service import Service service = Service(r"D:\WebSpider\venv\Scripts\geckodriver.exe")
service.start()
driver = webdriver.Remote(service.service_url)
driver.get('http://www.chaojiying.com/user/login/')
官方文档中给到的介绍,指定chromedrive的路径,但是实测通过这种方式打开网页还是闪退
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service('/path/to/chromedriver')
service.start()
driver = webdriver.Remote(service.service_url)
driver.get('http://www.google.com/');
time.sleep(5) # Let the user actually see something!
driver.quit()

4.尝试更换浏览器为火狐的,使用最新版的火狐浏览器,直接对应也是最新的火狐驱动
firefox驱动下载链接:https://gitHub.com/mozilla/geckodriver/releases
火狐浏览器版本:101.0.1 (64 位)
火狐驱动版本:0.31.0 (2022-04-11, b617178ef491)
尝试使用指定火狐驱动打开之前写的程序,测试成功,问题还是出在了chrome浏览器中
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from chaojiying import Chaojiying_Client
import time web = Firefox() web.get("http://www.chaojiying.com/user/login/")
# 处理验证码
img = web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png chaojiying = Chaojiying_Client('18312341234', '123456', '912345')
dic = chaojiying.PostPic(img,1902)
verify_code = dic['pic_str'] # 想页面中填入用户名,密码验证码
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys("183312341234")
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys("123456")
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(verify_code) #点击登录
time.sleep(5)
web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click() # driver.quit()

python:selenium测试登录在chrome中闪退的更多相关文章
- 使用Python+Selenium模拟登录QQ空间
使用Python+Selenium模拟登录QQ空间爬QQ空间之类的页面时大多需要进行登录,研究QQ登录规则的话,得分析大量Javascript的加密解密,这绝对能掉好几斤头发.而现在有了seleniu ...
- python+selenium遍历某一个标签中的内容
一.python+selenium遍历某一个标签中的内容 举个例子:我要获取列表标签<li></li>的内容 根据python+selenium定位到列表整体,使用for循环获 ...
- Python+selenium测试环境成功搭建,简单控制浏览器(firefox)接下来,继续学习其他浏览器上的测试环境搭建;学习Python语言,利用Python语言来写测试用例。加油!!!
Python+selenium测试环境成功搭建,简单控制浏览器(firefox)接下来,继续学习其他浏览器上的测试环境搭建:学习Python语言,利用Python语言来写测试用例.加油!!!
- python+selenium自动化登录dnf11周年活动界面领取奖励登录部分采坑总结[1]
背景: Dnf的周年庆活动之一,游戏在6月22日 06:00~6月23日 06:00之间登陆过游戏后可以于6月25日 16:00~7月04日 06:00领取奖励 目标:连续四天自动运行脚本,自动领取所 ...
- Python + Selenium 实现登录Office 365
最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...
- python selenium 测试环境的搭建及python mysql的连接
又来一篇傻瓜教程啦,防止在学习的小伙伴们走弯路. 1.python 环境搭建 python官网:https://www.python.org/downloads/ 选择最新版本python下载(如果 ...
- 【python+selenium自动化】设置Chrome启动参数
起因:直接用selenium的webdriver启动chrome,会弹出“Chrome正在受到自动软件的控制”,并且窗口较小,是因为chrome没有加载任何配置 解决:点进selenium的Chrom ...
- Python+Selenium:初步使用Chrome谷歌浏览器
·············环境结合··············· 我的环境:window10 64位 Python 3.7 32-bit selenium 3.141.0 Goo ...
- python selenium 测试浏览器(IE,FF,Chrome)
browser_engine.py # coding=utf-8 from selenium import webdriver class BrowserEngine(object): "& ...
随机推荐
- P7683 [COCI2008-2009#5] KRUSKA
洛谷上这道题的第一篇题解.上海加油. 题目大意 Aladdin 已经厌倦了宫殿里的生活.他有一份稳定的工作,他的妻子 Jasmine 和孩子们都在路上,生活变得单调.在这一切的驱使下,他决定在安顿下来 ...
- TNS-12533: TNS:illegal ADDRESS parameters(修复)
修复 TNS-12533: TNS:illegal ADDRESS parameters oracle@prd:/home/oracle$sqlplus sys/abc@fp as sysdba SQ ...
- BI系统打包Docker镜像及容器化部署的具体实现
在过去的几年中,"云"作为明星热词站在了各种新潮技术之中,你可能使用过,但说不清它的原理:或者是没用过,但听过它的大名:也可能连它的名字都没听过,但你对这只蓝色鲸鱼一定十分眼熟.作 ...
- Python 连接Mysql数据库执行语句操作
学习Mysql模块的使用,模块命名的坑,解决SHA加密错误无法连接
- 2022.02.20 SA
2022.02.20 SA 如果我还能看见明天黎明,如果我还能再爬起来,我仍会走我的路,哪怕这条路已经荒废许久,也许我们无法拥有感情,我们甚至无法像个正常人一样接受太阳的洗礼,但是我依然会执行我的条约 ...
- Android四大组件——Activity——Activity之间通信上
Activity之间的跳转有显式意图和隐式意图两种. 显式意图(显式Intent): //创建一个Intent对象,明确Intent跳转时的源Activity和目标Activity.参数一为当前Act ...
- qt在linux下引用x11库编译错误的解决办法
首先安装x11的开发包,以debian9为例:sudo apt install xorg-dev这个解决.h头文件和.a库文件在qt的.pro文件中加入:LIBS += -lX11这个解决连接错误,注 ...
- Apache Doris ODBC Mysql外表在Ubuntu下使用方法及配置
Apache Doris 社区 2022 年的总体规划,包括待开展或已开展.以及已完成但需要持续优化的功能.文档.社区建设等多方面,我们期待有更多的小伙伴参与进来讨论.同时也希望多多关注Doris,给 ...
- Luffy /3/ 前台主页搭建&轮播图接口
目录 前台主页搭建 components/Homeviwe.vue components/Banner.vue components/Header.vue components/Footer.vue ...
- rocketmq消息及流程
1.为什么用mq 优势 主要有3个: 应用解耦(降低微服务之间的关联). 异步提速(微服务拿到mq消息后同时工作). 削峰填谷(可以消息堆积) 劣势 系统可用性降低(MQ一旦宕机整个系统不可用) 复杂 ...