- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I capture network traffic of a specific page using Selenium?
We can capture network traffic on a specific page using Selenium webdriver in Python. To achieve this, we take the help of the JavaScript Executor. Selenium can execute JavaScript commands with the help of the execute_script method.
JavaScript command to be executed is passed as a parameter to this method. To capture the network traffic, we have to pass the command: return window.performance.getEntries() as a parameter to the execute_script method.
Syntax
r = driver.execute_script("return window.performance.getEntries();")
Example
Code Implementation
from selenium import webdriver #configure chromedriver path driver = webdriver.Chrome(executable_path='../drivers/chromedriver') #implicit wait driver.implicitly_wait(0.5) #url launch driver.get("https://www.google.com/") #JavaScript command to traffic r = driver.execute_script("return window.performance.getEntries();") for res in r: print(res['name']) #browser close driver.close()
Output
- Related Articles
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- How can I scroll a web page using selenium webdriver in python?
- How can I close a specific window using Selenium WebDriver with Java?
- How can I check if some text exist or not in the page using Selenium?
- How to capture tooltip in Selenium using getAttribute?
- How to capture tooltip in Selenium using Actions Class?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to capture screenshots in Selenium?
- How to get content of entire page using Selenium?
- How can I download a file on a click event using selenium?
- How can I count visitors per page per day using MySQL?
- How can I parse a website using Selenium and Beautifulsoup in python?
- How can I select date from a datepicker div using Selenium Webdriver?
- How can I verify Error Message on a webpage using Selenium Webdriver?
- How can I handle multiple keyboard keys using Selenium Webdriver?

Advertisements