栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

selenium macOS

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

selenium macOS

系列文章目录

selenium


macOS selenium
  • 系列文章目录
  • 前言
  • 一、ChromeDriver下载
    • 方法2 通过brew安装
  • 二、安装selenium
    • 1.pip
  • 三、selenium基本使用
    • 2.测试
    • 3. 打开百度搜索内容
  • 参考


前言

selenium:Web应用程序测试工具


一、ChromeDriver下载

ChromeDriver
chromedriver_mac64_m1.zip

  • Latest stable release: ChromeDriver 102.0.5005.61
方法2 通过brew安装

chromedriver

brew install --cask chromedriver
╰─➤  brew install --cask chromedriver                                                                                                                                                1 ↵
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 6 taps (homebrew/cask-versions, homebrew/command-not-found, homebrew/core, homebrew/cask, homebrew/cask-fonts and homebrew/cask-drivers).
==> New Formulae
bore-cli                  dtrx                      flix                      hatch                     naml                      terramate                 xpipe
cxgo                      erlang@24                 gokart                    helmify                   opentelemetry-cpp         tinysearch
==> Updated Formulae
Updated 398 formulae.
==> New Casks
bili-downloader                cardpresso                     hdfview                        oso-cloud                      rustdesk                       xmind8
bilibili-official              contour                        input-source-pro               roam-research                  swiftcord
==> Updated Casks
Updated 335 casks.
==> Deleted Casks
coarchi                                       font-gentium-plus-book                        race-into-space                               xmind-zen
crystax-ndk                                   plistedplus                                   stubbymanager                                 yammer

==> Downloading https://chromedriver.storage.googleapis.com/102.0.5005.61/chromedriver_mac64_m1.zip
######################################################################## 100.0%
==> Installing Cask chromedriver
==> Linking Binary 'chromedriver' to '/opt/homebrew/bin/chromedriver'
  chromedriver was successfully installed!
╰─➤  chromedriver --version

╰─➤  chromedriver --version
ChromeDriver 102.0.5005.61 (0e59bcc00cc4985ce39ad31c150065f159d95ad3-refs/branch-heads/5005@{#819})
二、安装selenium 1.pip
╰─➤  pip install selenium
  • 验证
╰─➤  python
Python 3.9.12 (main, May  8 2022, 17:57:49)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import selenium
>>>
三、selenium基本使用 2.测试

test01.py

from selenium import webdriver

driver = webdriver.Chrome()
base_url = 'https://www.baidu.com'
driver.get(base_url)
3. 打开百度搜索内容
from selenium import webdriver
import time

# 创建浏览器对象
driver = webdriver.Chrome()

# 打开浏览器
url = 'https://www.baidu.com'
driver.get(url)

time.sleep(2)
# 获取输入框对象
input = driver.find_element_by_id("kw")
# 输入内容
input.send_keys("macos")

time.sleep(2)
# 获取点击按钮对象
button = driver.find_element_by_id("su")
# 点击按钮
button.click()

time.sleep(5)
# 退出浏览器
driver.quit()

参考
  1. ChromeDriver
  2. chromedriver_mac64_m1.zip
  3. 尚硅谷Python爬虫教程小白零基础速通(含python基础+爬虫案例)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/934250.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号