- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 to 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.
- Related Articles
- How could I start a Selenium browser(like Firefox) minimized?
- How to launch Edge browser with Selenium Webdriver?
- How to handle proxy in Selenium in Java?
- Browser Plugin Testing With Selenium.
- Use Selenium with Chromium Browser.
- Running Selenium Webdriver with a proxy in Python.
- How does selenium interact with the Web browser?
- How to invoke the Chrome browser in Selenium with python?
- How to invoke the Firefox browser in Selenium with python?
- How to invoke the IE browser in Selenium with python?
- How to close a browser session in Selenium with python?
- How to set Proxy in Firefox using Selenium WebDriver?
- How to perform browser navigations in Selenium?
- How to maximize the browser in Selenium?
- How to launch Chrome Browser via Selenium?
