问题描述:使用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中闪退的更多相关文章

  1. 使用Python+Selenium模拟登录QQ空间

    使用Python+Selenium模拟登录QQ空间爬QQ空间之类的页面时大多需要进行登录,研究QQ登录规则的话,得分析大量Javascript的加密解密,这绝对能掉好几斤头发.而现在有了seleniu ...

  2. python+selenium遍历某一个标签中的内容

    一.python+selenium遍历某一个标签中的内容 举个例子:我要获取列表标签<li></li>的内容 根据python+selenium定位到列表整体,使用for循环获 ...

  3. Python+selenium测试环境成功搭建,简单控制浏览器(firefox)接下来,继续学习其他浏览器上的测试环境搭建;学习Python语言,利用Python语言来写测试用例。加油!!!

    Python+selenium测试环境成功搭建,简单控制浏览器(firefox)接下来,继续学习其他浏览器上的测试环境搭建:学习Python语言,利用Python语言来写测试用例.加油!!!

  4. python+selenium自动化登录dnf11周年活动界面领取奖励登录部分采坑总结[1]

    背景: Dnf的周年庆活动之一,游戏在6月22日 06:00~6月23日 06:00之间登陆过游戏后可以于6月25日 16:00~7月04日 06:00领取奖励 目标:连续四天自动运行脚本,自动领取所 ...

  5. Python + Selenium 实现登录Office 365

    最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...

  6. python selenium 测试环境的搭建及python mysql的连接

    又来一篇傻瓜教程啦,防止在学习的小伙伴们走弯路. 1.python 环境搭建 python官网:https://www.python.org/downloads/  选择最新版本python下载(如果 ...

  7. 【python+selenium自动化】设置Chrome启动参数

    起因:直接用selenium的webdriver启动chrome,会弹出“Chrome正在受到自动软件的控制”,并且窗口较小,是因为chrome没有加载任何配置 解决:点进selenium的Chrom ...

  8. Python+Selenium:初步使用Chrome谷歌浏览器

    ·············环境结合··············· 我的环境:window10 64位 Python 3.7 32-bit selenium            3.141.0 Goo ...

  9. python selenium 测试浏览器(IE,FF,Chrome)

    browser_engine.py # coding=utf-8 from selenium import webdriver class BrowserEngine(object): "& ...

随机推荐

  1. 微信小程序插件组件-Taro UI

    微信小程序组件使用以下官网查看 ↓  ↓  ↓ https://taro-ui.jd.com/#/docs/fab

  2. springcloud报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'armeriaServer' defined in class path resource

    spring boot配置zipkin 无法启动 加入 Zipkin Server 由于需要收集 Spring Cloud 系统的跟踪信息,以便及时地发现系统中出现的延迟升高问题并找出系统性能瓶颈的根 ...

  3. JAVASE Scanner

    package com.huang.boke.flowPath;import java.util.Scanner;public class test01 { public static void ma ...

  4. linux磁盘概述

    硬盘简史 世界上第一块硬盘出生在1956年,至今已有61年半个多世纪的历史.它由IBM公司制造,世界上第一块硬盘:350RAMAC.盘片直径为24英寸,盘片数为50片,重量则是上百公斤,相当于两个冰箱 ...

  5. Ubu18下cpptest安装

    1.环境安装 sudo apt install g++ sudo apt install automake sudo apt install autoconf sudo apt install lib ...

  6. SpringCloud微服务实战——搭建企业级开发框架(三十九):使用Redis分布式锁(Redisson)+自定义注解+AOP实现微服务重复请求控制

      通常我们可以在前端通过防抖和节流来解决短时间内请求重复提交的问题,如果因网络问题.Nginx重试机制.微服务Feign重试机制或者用户故意绕过前端防抖和节流设置,直接频繁发起请求,都会导致系统防重 ...

  7. shell语法习题练习进阶版

    第4章 shell语法深度习题练习 4.1 使用if,case,函数的方法将服务改成system(centos6) 4.1.1 if方法 4.1.1.1 system实现 4.1.1.1.1 编写代码 ...

  8. PAT练习——1094 The Largest Generation (25 point(s))

    题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...

  9. XCTF练习题---MISC---Test-flag-please-ignore

    XCTF练习题---MISC---Test-flag-please-ignore flag:flag{hello_world} 解题步骤: 1.观察题目,下载附件 2.打开文件,发现又是一个没有名字的 ...

  10. Kubernetes 从入门到进阶实战教程 (2021 最新万字干货版)

    作者:oonamao 毛江云,腾讯 CSIG 应用开发工程师原文:来源腾讯技术工程,https://tinyurl.com/ya3ennxf 写在前面 笔者今年 9 月从端侧开发转到后台开发,第一个系 ...