【Python】使用Selenium 操作浏览器 自动化测试 记录

【自动化】Python SeleniumUtil 工具 开启开发者模式 自动安装油猴用户脚本等-CSDN博客文章浏览阅读389次。【自动化】Python SeleniumUtil 工具。https://blog.csdn.net/G971005287W/article/details/144565691?spm=1001.2014.3001.5501【学习记录】浏览器指纹相关学习记录(指纹介绍、获取指纹、修改指纹、随机指纹保护隐私等)-CSDN博客文章浏览阅读1k次,点赞30次,收藏11次。可以识别是同一个用户。https://blog.csdn.net/G971005287W/article/details/144528762【自动化】Python SeleniumUtil 油猴 工具 自动安装用户脚本-CSDN博客文章浏览阅读311次。【自动化】Python SeleniumUtil 工具-CSDN博客。【自动化】Python SeleniumUtil 油猴 工具。【自动化】Python SeleniumUtil 工具。https://blog.csdn.net/G971005287W/article/details/144565736

【Python】使用Selenium 操作浏览器 记录

1.安装python

2.安装 selenium

复制代码
pip install selenium

3.安装Chrome浏览器驱动

【附件】Selenium chromedriver 驱动及浏览器下载-CSDN博客文章浏览阅读42次。【附件】Selenium chromedriver 驱动及浏览器下载。https://blog.csdn.net/G971005287W/article/details/144556634

python 复制代码
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.edge.options import Options as EdgeOptions
import time



def main():
    # 设置Edge选项
    edge_options = EdgeOptions()
    edge_options.add_argument('--start-maximized')  # 窗口最大化启动
    user_data_dir = r'C:\Users\Administrator\AppData\Local\Microsoft\Edge\User Data'  # Windows 示例路径,请替换为实际路径
    edge_options.add_argument(f'--user-data-dir={user_data_dir}')  # 窗口最大化启动

    # 如果需要指定Profile,可以添加 --profile-directory 参数
    # profile_directory = 'Profile 5'  # 替换为你要使用的具体Profile名称
    profile_directory = 'Default'  # 替换为你要使用的具体Profile名称
    edge_options.add_argument(f'--profile-directory={profile_directory}')

    # edge_options.add_argument("--headless")
    # 指定Edge WebDriver的位置
    service = EdgeService(executable_path='C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver.exe')
    # service = EdgeService(executable_path=executable_path)
    # 创建一个新的Edge浏览器实例,并启用无痕模式
    driver = webdriver.Edge(service=service, options=edge_options)
    driver.set_window_size(300, 500)
    # 打开目标网页
    driver.get('https://www.baidu.com')
    print('打开第一个浏览器')


    # 设置Edge选项
    edge_options2 = EdgeOptions()
    edge_options2.add_argument('--start-maximized')  # 窗口最大化启动
    # edge_options2.add_argument("--headless")
    user_data_dir2 = r'C:\Users\Administrator\AppData\Local\Microsoft\Edge\User Data2'  # Windows 示例路径,请替换为实际路径
    edge_options2.add_argument(f'--user-data-dir={user_data_dir2}')  # 窗口最大化启动

    # 如果需要指定Profile,可以添加 --profile-directory 参数
    # profile_directory2 = 'Profile 5'  # 替换为你要使用的具体Profile名称
    profile_directory2 = 'Default'  # 替换为你要使用的具体Profile名称
    edge_options2.add_argument(f'--profile-directory={profile_directory2}')


    # 指定Edge WebDriver的位置
    service2 = EdgeService(executable_path='C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedgedriver2.exe')
    # service = EdgeService(executable_path=executable_path)
    # 创建一个新的Edge浏览器实例,并启用无痕模式
    driver2 = webdriver.Edge(service=service2, options=edge_options2)
    driver2.set_window_size(300, 500)
    # 打开目标网页
    driver2.get('https://www.baidu.com')
    print('打开第二个浏览器')
    time.sleep(500000000)

if __name__ == "__main__":
    main()
相关推荐
小冯的编程学习之路8 小时前
【软件测试】:推荐一些接口与自动化测试学习练习网站(API测试与自动化学习全攻略)
c++·selenium·测试工具·jmeter·自动化·测试用例·postman
Ten peaches11 小时前
Selenium-Java版(操作元素)
java·selenium·测试工具·html
傻小胖14 小时前
三种常见接口测试工具(Apipost、Apifox、Postman)
测试工具·postman
辛普森Mmmm16 小时前
Postman接口测试
测试工具·postman
程序员三藏17 小时前
软件测试之功能测试详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
Looooking21 小时前
Python 之 selenium 打开浏览器指定端口进行接续操作
python·selenium
头疼的程序员1 天前
allure生成测试报告(搭配Pytest、allure-pytest)
测试工具·pytest
程序员杰哥2 天前
自动化测试基础知识详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
程序员小远2 天前
自动化测试与功能测试详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
第三方软件测评3 天前
第三方软件测评中心分享:软件功能测试类型和测试工具
功能测试·测试工具