安装selenium ide
阿里云盘下载插件 打开插件开发这模式 拖拽安装
阿里云盘分享不了 如需获取 加qq 2398249461 免费分享
使用selenium ide
create a new project 名称为 first_project
1、输入网址 www.baidu.com
2、点击rec按钮进行录制
3、点击停止按钮 停止录制 命名案列名称
4、导出脚本
生成的代码如下:
# Generated by Selenium IDE
import pytest
import time
import json
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 setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def wait_for_window(self, timeout = 2):
time.sleep(round(timeout / 1000))
wh_now = self.driver.window_handles
wh_then = self.vars["window_handles"]
if len(wh_now) > len(wh_then):
return set(wh_now).difference(set(wh_then)).pop()
def test_test01(self):
self.driver.get("https://www.baidu.com/")
self.driver.set_window_size(813, 473)
self.driver.find_element(By.ID, "kw").click()
self.driver.execute_script("window.scrollTo(0,0)")
self.driver.find_element(By.ID, "kw").send_keys("selenium")
self.driver.find_element(By.ID, "kw").send_keys(Keys.ENTER)
self.driver.execute_script("window.scrollTo(0,0)")
self.vars["window_handles"] = self.driver.window_handles
self.driver.find_element(By.LINK_TEXT, "Selenium(WEB自动化工具) - 百度百科").click()
self.vars["win5576"] = self.wait_for_window(2000)
self.driver.switch_to.window(self.vars["win5576"])
安装pytest
安装成功
运行刚导出的脚本