如何使用selenium ide录制一个脚本

录制脚本

安装 selenium ide使用火狐浏览器

如何使用selenium ide录制一个脚本_第1张图片
如何使用selenium ide录制一个脚本_第2张图片
安装
如何使用selenium ide录制一个脚本_第3张图片
这样就可以录制我们的脚本了

开始录制脚本

1.firefox右上角,点击selenium IDE图标,进入selenium IDE界面;
如何使用selenium ide录制一个脚本_第4张图片

2.进入selenium IDE界面,首先我们选择创建项目,我们直接选择Create a new project
如何使用selenium ide录制一个脚本_第5张图片

3.输入项目名称,点击ok;
如何使用selenium ide录制一个脚本_第6张图片
4.修改文件名 :
如何使用selenium ide录制一个脚本_第7张图片
5.开始录制:
如何使用selenium ide录制一个脚本_第8张图片

6.输入url,点击start recording;
如何使用selenium ide录制一个脚本_第9张图片
7.firefox会打开输入的url地址页面并进行录制
如何使用selenium ide录制一个脚本_第10张图片

8.此时,对浏览器进行一系列的操作,selenium IDE会记录所有的操作,比如在搜索框中输入刘亦菲并进行查询;
如何使用selenium ide录制一个脚本_第11张图片

9.结束录制。在selenium IDE界面右上角,点击结束录制图标,
如何使用selenium ide录制一个脚本_第12张图片
10.导出录制的脚本。点test1右边的三个点,选择export;
如何使用selenium ide录制一个脚本_第13张图片
11.这里提供多种语言的脚本导出,选择需要导出的语言,然后点击export即可,我选择的是 Python pytest 然后点击export
如何使用selenium ide录制一个脚本_第14张图片
12.导出后的脚本内容如下:

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 TestTest1():
  def setup_method(self, method):
    self.driver = webdriver.Firefox()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def test_test1(self):
    self.driver.get("https://www.baidu.com/")
    self.driver.set_window_size(638, 680)
    self.driver.find_element(By.ID, "kw").click()
    self.driver.find_element(By.ID, "kw").send_keys("刘亦菲")
    self.driver.find_element(By.ID, "kw").send_keys(Keys.ENTER)
  

这样就成功录制一个脚本了

你可能感兴趣的:(基于python的自动化测试,测试,selenium)