- 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
Running Selenium Webdriver with a proxy in Python.
We can run a proxy with Selenium webdriver in Python. A proxy is an essential component to do localization testing. We can take an e-commerce application and check if the language and currency visible is as per the user location.
With the help of proxy within tests, we can verify if the website user interface matches with the location. We have to SET a proxy with below steps −
Import webdriver from Selenium package.
Define proxy server address.
Create an object of ChromeOptions class
Communication of proxy with ChromeOptions.
Summing options to Chrome() object.
Example
Code Implementation.
from selenium import webdriver #proxy server definition py = "128.21.0.0:8080" #configure ChromeOptions class chrome_options = WebDriverWait.ChromeOptions() #proxy parameter to options chrome_options.add_argument('--proxy-server=%s' % py) #options to Chrome() driver = webdriver.Chrome(chrome_options= chrome_options) driver.implicitly_wait(0.6) driver.get("https://www.tutorialspoint.com/index.htm")
Then, to check if a search field has the present user address we shall add the below code snippet −
def checkL(self): self.driver.get(self.url) st = self.driver.find_element_by_xpath('#loc') #check location with assertion self.assertEqual('India', st.text)
If we have to verify more than locations, we can create a method and pass the proxy address as an argument.
- Related Articles
- Running Selenium WebDriver python bindings in chrome.
- How to set Proxy in Firefox using Selenium WebDriver?
- How install Selenium Webdriver with Python?
- How to start selenium browser with proxy?
- Is navigate method available in Selenium Webdriver with Python?
- Running javascript in Selenium using Python.
- How do you automatically download a Pdf with Selenium Webdriver in Python?
- How to take partial screenshot with Selenium WebDriver in python?
- Maximize WebDriver (Selenium 2) in Python.
- How can I manually set proxy settings in Python Selenium?
- Selenium WebDriver With Java Quickstart.
- How to set a cookie to a specific domain in selenium webdriver with Python?
- How to Select date from a datepicker with Selenium Webdriver using Python?
- Handle Firefox Not Responding While Using Selenium WebDriver With Python?
- How to get selected option using Selenium WebDriver with Python?
