当前位置:网站首页>Webui automated learning
Webui automated learning
2022-07-02 10:22:00 【Lost ~ know to return】
WebUI Automated learning
selenium Basics
selenium Introduce
selenium Drive browser
- selenium -- The mainstream version is 4.1 Is in 2021 year 10 The version available for download and use in January --last 3:3.141
- selenium == 4.1 -->python 3.8/python 3.9
- Selenium The core is JS Core Realized
- FireFox Plug in form of , named Selenium Plug in form of , named SeleniumIDE There is
- In order to make it easier for more browsers to use Selenium technology , So it's updated to Selenium2 edition , That is to say Selenium + webdrive Technical system , adopt WebDrive To control the browser , adopt Selenium To operate the browser
- As time goes on Selenium3 Version of , This is also the oldest version , The core is based on Selenium + WebDrive Form to realize all automatic interactions
- 2021 year 10 month , Officially launched Selenium4 Version of , Optimized the underlying structure , Added new wiping behavior , Weapon has some less commonly used content
- Now? SeleniumIDE There are new updates , Support the recording and playback of all kinds of browser on-line scripts ,
Selenium + WebDriver
Environment building :
- install python3.7 And above
- pip install selenium
- install WebDriver:http://chromedriver.storage.googleapis.com/index.html?path=100.0.4896.60/, Make sure ChromeDriver.exe It is consistent with the browser version
- decompression ChromeDriver.exe File to Python Installation path for
- If you worry about browsers and driver Versions are prone to mismatches , By using safedriver To automatically match your browser with driver edition , Installation method pip install safedriver
- pip In the process read timeout error Add domestic image source , Or set the maximum timeout --default-timeout=1000
- Verify that the environment is deployed successfully
- The test can be successful by coding the basic content
from selenium import webdriver
driver = webdriver.Chrome()
python + webdriver Realization UI automation
Basic operation
#coding:utf-8
""" selenium Deployed applications Jingdong search """
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# Create a browser , Start the browser based on the driver , Creation time , adopt session To manage browsers
drive = webdriver.Chrome()
# Visit Jingdong's url:get Function requires input url It must be complete ,http:// The prefix of cannot be cancelled
drive.get('http://www.jd.com')
# Then input the search content you want to input
# Find the input box , Do not use find_element_by_*
el = drive.find_element("id", 'key')
# Enter in the input box
el.send_keys('iphone13')
# Find the search button , Click on
el1 = drive.find_element("xpath", '//button[@aria-label=" Search for "]')
el1.click()
# wait for 3s
time.sleep(10)
drive.quit()
selenium Operation principle
code -> webdriver -> chrome
Essentially, code–> start-up chrome(webdriver.chromedrive)–> Call the local browser
webdriver.chromedrive --> Intermediate agent
The data returned : browser –>webdrivedriver->code
The source code parsing :
# be based on driver The bottom layer realizes Baidu search
# coding:utf-8
import time
from selenium.webdriver.chrome.webdriver import WebDriver
# Generate browser objects , By generated webdriver object , Start the default Google browser
driver = WebDriver(executable_path="chromedriver")
# Visit the website , The underlying code , adopt command Command to call get Method , And implement http://www.baidu.com Get the return value
driver.execute('get', {
'url': 'http://www.baidu.com'})
# Element positioning of input box , Through the browser driver to achieve find_element Method search
el = driver.execute('findElement', {
'using': 'css selector',
'value': '[id="kw"]'})['value']
el._execute('sendKeysToElement', {
'text': " Shenzhou 13 ", 'value': ""})
el_1 = driver.execute('findElement', {
'using': 'css selector',
'value': '[id="su"]'})['value']
el_1._execute('clickElement')
time.sleep(10)
driver.execute('quit')
html Basics
The components are divided into three :
- Tag name (TagName)
- attribute (Attribute)
- Text (text)
Common labels :a/div/span/i/tr/td/input/p/form…
Don't believe in granulation reduction in the form of elements , It should be determined based on the attributes of the element
Text is not something that every tag has
<input>Text</input>
<input/>
<input></input>
selenium And 8 Large element positioning method
find_element_by_id
Positioning method of relative path :
Rule of grammar ://[@id=“kw”], Search from the root path id attribute , And the attribute value is kw The elements of
// Look under the root path , Represents any element , filter ,[] Add filter ,@ Means to search based on attributes ,id Represents the name of the property ,kw Represents the value of the property
text() Indicates text-based positioning
//[contains(text(),'‘)] Based on contains Function for fuzzy matching of data
Find adjacent elements
//*[contains(’‘,’')]/follow-sibling::span– Find the sibling element of the current element
xpath The way you write , Remove to avoid heap path accidents , It can also avoid the failure of element positioning caused by dynamic elements
Pseudo elements (::before:::after::)
Tag name
selenium The basic operation of the window
# coding:utf-8
from selenium import webdriver
# Form maximization , Use chrome——op
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
# chrome Browser configuration , Starting is maximizing
driver = webdriver.Chrome(options=options)
# Form maximization , stay selenium2 There's one in the beginning bug, Calling form maximization will cause driver Timeout exception for
# driver.maximize_window()
# Set the size of the form
driver.set_window_size(200, 1000)
driver.get('http://39.98.138.157/shopxo/index.php')
边栏推荐
- [ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)
- Postman--使用
- [IDL] Research
- 【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
- How to judge the quality of primary market projects when the market is depressed?
- 【Unity3D】无法正确获取RectTransform的属性值导致计算出错
- SAP Spartacus express checkout design
- Vscode set JSON file to format automatically after saving
- Project practice, redis cluster technology learning (11)
- Blender石头雕刻
猜你喜欢
随机推荐
Matlab生成dsp程序——官方例程学习(6)
测试--面试题总结
go语言入门
Blender stone carving
VLAN experiment
Alibaba cloud Prometheus monitoring service
【Unity3D】无法正确获取RectTransform的属性值导致计算出错
High level application of SQL statements in MySQL database (II)
【避坑指南】使用UGUI遇到的坑:Text组件无法首行缩进两格
[200 Shengxin literatures] 96 joint biomarkers of immune checkpoint inhibitor response in advanced solid tumors
07数据导入Sqoop
Centos7 one click compilation and installation of PHP script
【虚幻4】从U3D到UE4的转型之路
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
pytest--之测试报告allure配置
Postman--使用
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
Blender摄像机环绕运动、动画渲染、视频合成
高考那些事
Following nym, the new project Galaxy token announced by coinlist is gal