当前位置:网站首页>Web automation: summary of special scenario processing methods
Web automation: summary of special scenario processing methods
2022-06-24 21:05:00 【gchh_ spring】
web Automate special scenarios :
1、 Browser reuse scenarios (chrome browser )
2、 Use cookie Complete the automatic login of the page
3、
Browser reuse scenarios (chrome browser )
Browser reuse steps :
1、 Get into chrome The installation path of the browser , And open in this path cmd Command line , Enter the following command :
chrome --remote-debugging-port=9222

This command is equivalent to opening chrome A debugging web page , Don't close pages opened in this way ,
2、 adopt python The code implements the direct reuse steps when the browser is opened 1 Debugging web page opened in , Code in definition webdriver Variable passed in options Parameters
chrome_args = webdriver.ChromeOptions()
chrome_args.debugger_address = "127.0.0.1:9222"
self.driver = webdriver.Chrome(options=chrome_args)Be careful : Before executing the code, you need to put all chrome Web page closed , Then reopen the debug page , Then run the reusable browser code ; If you have previously opened a non debug chrome Webpage , It will cause the code to get stuck
3、 If your web page needs to scan the code to log in , Then you can login in the debug browser web page first , Use steps 2 After reusing the browser , You can directly locate elements , So you can omit the login step
Use cookie Complete the automatic login of the page
cookie: It is a data cache or identity of the browser , stay cookie Without failure , The server can use the browser's cookie Data realizes the automatic login of users ,cookie The validity of is determined by the server
selenium Provides a way to get the current page directly cookie Method of information , Just take what you get cookie Data saved , Then reuse the cookie Can realize the automatic login of the web page
1、 First, log in to the web page by yourself , Through the code to get the web page cookie Information , And save to json In file
class TestLogin:
def setup_method(self):
chrome_args = webdriver.ChromeOptions()
chrome_args.debugger_address = "127.0.0.1:9222"
self.driver = webdriver.Chrome(options=chrome_args)
def test_getcookies(self):
# Use the browser to debug the web page after logging in , Get the web page directly cookie Information
cookies = self.driver.get_cookies()
# Will get cookie Information written to cookies.json In file
with open("cookies.json", "w") as f:
json.dump(cookies, f)2、 from json File read cookie Information , Realize the automatic login of web pages
def test_login(self):
# First open the page you want to log in to ( Not logged in )
self.driver.get("https://work.weixin.qq.com/")
# Read cookie Information
with open("cookies.json", "r") as f:
cookies = json.load(f)
# adopt add_cookie Methods to inject cookie,add_cookie Method to open the web page to be injected before injection , Is the first line of code
for cookie in cookies:
self.driver.add_cookie(cookie)
# After injection , Reopen the login page
self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
self.driver.find_element_by_id("menu_contacts").click()
sleep(3)
边栏推荐
- Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
- A/b test helps the growth of game business
- Pyaudio audio recording
- Popupwindow touch event transparent transmission scheme
- Several common command operations in win system
- 浅谈MySql update会锁定哪些范围的数据
- 全上链哈希游戏dapp系统定制(方案设计)
- "Ningwang" was sold and bought at the same time, and Hillhouse capital has cashed in billions by "selling high and absorbing low"
- Basic operation of sequence table
- How Fiddler works
猜你喜欢

How to apply agile development ideas to other work

网络安全审查办公室对知网启动网络安全审查

What does virtualization mean? What technologies are included? What is the difference with private cloud?

Wechat applet custom tabbar
![[performance tuning basics] performance tuning strategy](/img/83/be41a6a0c5c186d3fb3a120043c53f.jpg)
[performance tuning basics] performance tuning strategy

Two fellow countrymen from Hunan have jointly launched a 10 billion yuan IPO

Does the developer want to change to software testing?

得物多活架构设计之路由服务设计

"Ningwang" was sold and bought at the same time, and Hillhouse capital has cashed in billions by "selling high and absorbing low"

微信小程序中使用vant组件
随机推荐
传统的IO存在什么问题?为什么引入零拷贝的?
Can the OPDS SQL component pass process parameters to the next component through context
I feel that I am bald again when I help my children with their homework. I feel pity for my parents all over the world
Material management system based on SSM (source code + document + database)
Vant component used in wechat applet
Talking about the range of data that MySQL update will lock
Power apps Guide
Second understanding permutation and combination
Leetcode(455)——分发饼干
等保备案是等保测评吗?两者是什么关系?
Learn to use a new technology quickly
After idea installs these plug-ins, the code can be written to heaven. My little sister also has to arrange it
Basic properties and ergodicity of binary tree
微信小程序自定义tabBar
Prototype mode -- clone monster Army
Postman assertion
Interpreter mode -- formulas for dating
A/B测试助力游戏业务增长
Builder mode -- Master asked me to refine pills
Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?