当前位置:网站首页>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)
边栏推荐
- Dx12 engine development course progress - where does this course go
- Apple doesn't need money, but it has no confidence in its content
- Nifi fast authentication configuration
- Bridging mode -- law firm
- C langage pour le déminage (version simplifiée)
- More than ten years' work experience is recommended at the bottom of the box: how much does it cost to find a job? See here! Brothers and sisters are recommended to collect and pay attention
- 二叉树的基本性质与遍历
- What does virtualization mean? What technologies are included? What is the difference with private cloud?
- Docker deploy mysql5.7
- Summary of idea practical skills: how to rename a project or module to completely solve all the problems you encounter that do not work. It is suggested that the five-star collection be your daughter
猜你喜欢

Nifi quick installation (stand-alone / cluster)

A/B测试助力游戏业务增长
浅谈MySql update会锁定哪些范围的数据

Variable setting in postman

Nifi fast authentication configuration

Sequential stack traversal binary tree

Intermediary model -- collaboration among departments

What are the problems with traditional IO? Why is zero copy introduced?

Agency mode -- Jiangnan leather shoes factory

Microsoft Certification (dynamic 365) test
随机推荐
物聯網?快來看 Arduino 上雲啦
Create a multithreaded thread class
Dx12 engine development course progress - where does this course go
伯克利、MIT、劍橋、DeepMind等業內大佬線上講座:邁向安全可靠可控的AI
Splicing audio files with ffmpeg-4.3
基于QT+MySQL的相机租赁管理系统
Variable setting in postman
Visitor model -- generation gap between young and middle-aged people
Simulation lottery and probability statistics experiment of the top 16 Champions League
Nifi fast authentication configuration
Reflection - class object function - get method (case)
Smooth live broadcast | analysis of key technologies for live broadcast pain points
It was Tencent who jumped out of the job with 26k. It really wiped my ass with sandpaper. It gave me a hand
Leetcode (146) - LRU cache
图的基本概念以及相关定义
After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked
The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time
Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
JMeter response assertion
Tool composition in JMeter