首页 > 编程语言 >解决Python报错OSError: [WinError 193] %1 不是有效的 Win32 应用程序

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

时间:2022-09-20 19:34:32浏览次数:72  
标签:WinError __ OSError 浏览器 driver step allure 报错 import

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

今天在练习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显示效果

  •  

     

     

     

      

 

标签:WinError,__,OSError,浏览器,driver,step,allure,报错,import
From: https://www.cnblogs.com/lili414/p/16712193.html

相关文章