
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
Start Selenium Browser with Proxy
We can start Selenium browser with proxy. The proxy server is an important tool to perform testing on localization. We can take an e-commerce site and verify that the language and currency displayed is as per the location of the user.
Using the proxy server within tests, we can test the look and feel of the site for a user belonging to a particular location. First of all, we have to configure an authenticated proxy server with below steps −
Importing the webdriver from the Selenium package.
Declare proxy server.
Configure ChromeOptions class
Clubbing proxy server to the ChromeOptions.
Pass options to Chrome() object.
Example
Code Implementation to configure a proxy server.
from selenium import webdriver #proxy server definition p = "127.20.0.0:8080" #configure ChromeOptions class chrome_options = WebDriverWait.ChromeOptions() #adding proxy parameter to options chrome_options.add_argument('--proxy-server=%s' % p) #adding options to Chrome driver = webdriver.Chrome(chrome_options= chrome_options) driver.implicitly_wait(0.5) driver.get("https://www.tutorialspoint.com/index.htm")
Next, to verify if a search field displays the present user address automatically we shall use the below code snippet −
def checkLocation(self): self.driver.get(self.url) s = self.driver.find_element_by_name('location') #verify location with assertion self.assertEqual('USA', s.text)
If we have to check more than locations, we can create a method and pass the proxy IP address as a parameter.