第一个python自动化实例

  1. 下载python安装

  2. 验证是否安装pip

python -m pip --version
输出如下,表示安装
pip 19.2.3 from C:\_Program\Python27\lib\site-packages\pip (python 2.7)
  1. 安装selenium
pip install selenium
  1. 查看chrome版本,然后到https://chromedriver.storage.googleapis.com/index.html下载对应的win32.zip
    解压zip文件,放在chrome浏览器根目录下
    验证是否安装:直接在cmd目录下执行chromedriver即可

  2. 配置环境变量,将chrome根目录和python根目录添加到环境变量中。

  3. 添加test.py文件,代码如下

# coding=utf-8

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class TestTest01():
  def __init__(self):
    self.driver = webdriver.Chrome()
    self.vars = {}

    def over(self):
        self.driver.quit()

	def test_test01(self):
		self.driver.get("https://www.baidu.com/")
		self.driver.set_window_size(1088, 816)
		self.driver.find_element(By.ID, "kw").send_keys("selenium")
		self.driver.find_element(By.ID, "kw").send_keys(Keys.ENTER)

obj = TestTest01()
obj.test_test01()
# obj.over()
  1. cmd窗口运行命令
python test.py
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值