python3.10+selenium4.9.1初始化安装踩坑记

2023年了,又开始捯饬web UI自动化。前些年appium写的比较多,现在又开始依据记忆中对于selenium的留存,开始练习用python来写。

一、安装

首先,pycharm安装、python3.10安装,python环境变量设置为前提条件。

python3.10默认就自带了selenium的,可以在pycharm->settings->Python Interpreter中查看到。如果非典型安装没有selenium,可以点+号添加。

安装chrome的驱动:

Chrome驱动下载地址:http://chromedriver.storage.googleapis.com/index.html

在chrome浏览器中查看当前chrome的版本,输入chrome://vesrion

在驱动下载中,搜113.0.5672

需要下载到python的scripts

二、编写demo脚本

# -*- coding: utf-8 -*-
"""
@Time : 2023/5/28 17:24
@Auth : xxx
"""
from selenium import  webdriver
print("hello world")

browser = webdriver.Chrome()
browser.get('https://www.baidu.com')
#通过id定位搜索框,并输入哈哈的内容
browser.find_element("id","kw").send_keys("哈哈")
先走通一个最基本的小单元

注意一点selenium 4.0+ ,之前的几个常用函数,例如find_element_by_id(),find_element_xx都没有了,现在只有 find_element() 和 find_elements()。

switch_to_frame(x), x是id或者name,现在变为 switch_to.frame(x)。参数是一样的。

三、进一步学习pageObject和pytest

进一步学习,初步学习pageObject模式和pytest测试框架,可以先通过chatGPT了解一个最小的单元,有个概念,可参考我的这篇文章:

使用chatGPT辅助学习pageobject和pytest

猜你喜欢

转载自blog.csdn.net/michelle_li08/article/details/131395631