
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.