zl程序教程

您现在的位置是:首页 >  后端

当前栏目

解决Python调试OSError: [WinError 193] %1 不是有效的 Win32 应用程序

Python调试应用程序 解决 有效 不是 Win32 OSError
2023-09-11 14:15:55 时间

今天在练习selenium运行后报错 ,网上找了很多方法,最终终于解决。

我的问题是 chromeDriver驱动不匹配。

解决步骤1:先打开谷歌浏览器查看我们的浏览器版本,在打开以下网址下载对应的 chromeDriver版本 ,https://chromedriver.storage.googleapis.com/index.html;

讲下载后的chromedriver.exe放到 python 安装包目录的\Python38\Scripts 下面

重新运行程序,打开浏览器正常,报错消失。

查看版本方法

在这里插入图片描述

下载浏览器对应的驱动版本

在这里插入图片描述

解压后保存目录

在这里插入图片描述

# coding=utf-8
'''
Author: 
Email: 
Version: V1.0.0
Date: 2022/9/19 
Desc:
'''

import pytest
import allure
import time
from selenium import webdriver
import os
from os.path import dirname


@allure.testcase("https://www.baidu.com的搜索功能")
@pytest.mark.parametrize('test_data1', ['allure', 'pytest', 'unittest'])
def test_steps_demo(test_data1):
    with allure.step('step one:打开浏览器'):
        a = dirname(dirname(__file__)) +os.sep+ '/driver/chromedriver'
        print(a)
        # driver = webdriver.Chrome(executable_path='C:\\Users\\user\\PycharmProjects\\testframework\\frameworkDemo\\driver\\chromedriver')
        driver = webdriver.Chrome()
        driver.get('https://www.baidu.com')

    with allure.step('step two:在搜索栏输入allure,并点击百度一下'):
        driver.find_element('id', 'kw').send_keys(test_data1)
        time.sleep(1)
        driver.find_element('id', 'su').click()
        time.sleep(1)

    with allure.step('step three:截图保存到项目中'):
        driver.save_screenshot('./result/b.png')
        allure.attach.file("./result/b.png", attachment_type=allure.attachment_type.PNG)
        allure.attach('<head></head><body> 首页</body>', 'Attach with HTML type', allure.attachment_type.HTML)

    with allure.step('step four:关闭浏览器'):
        driver.quit()


if __name__ == '__main__':
    pytest.main(['--alluredir=./report/', 'test_allure_screen.py'])
    os.system('allure serve ./report')

运行后allure显示效果

在这里插入图片描述

现在我邀请你进入我们的软件测试学习交流群:746506216】,备注“入群”, 大家可以一起探讨交流软件测试,共同学习软件测试技术、面试等软件测试方方面面,还会有免费直播课,收获更多测试技巧,我们一起进阶Python自动化测试/测试开发,走向高薪之路。

喜欢软件测试的小伙伴们,如果我的博客对你有帮助、如果你喜欢我的博客内容,请 “点赞” “评论” “收藏” 一 键三连哦!

在这里插入图片描述

在这里插入图片描述