A proxy can also add another layer of security on the web by acting as a firewall between Client and web servers. This is especially used when the websites that clients use have to be labeled as allowed or blocked based on the website content. This process is known as ‘Content Filtering’ and is most commonly used in Educational Institutions, Corporate Offices, etc. Content Filtering can be easily accomplished with the help of a proxy. In terms on the Internet, a proxy can be implemented as a separate server which stands in between client machines and actual web or database servers responding. In this tutorial, you will learn

What is a Proxy? Difference between SOCKS and HTTP Proxy
How to Handle Proxy in Selenium Webdriver in Chrome Using the AutoIT tool
Using Alerts

Difference between SOCKS and HTTP Proxy

How to Handle Proxy in Selenium Webdriver in Chrome

HTTP Proxy authentication with Selenium in Chrome can be handled using the following approaches

Using the AutoIT tool Using Alerts

Using the AutoIT tool

Auto IT is a third party tool that is used for windows desktop automation. Since Selenium only handles web-based popups and windows, handling operating system controls is not possible using Selenium. This requires the use of external third-party tools such as Auto IT to be integrated with Selenium. For that, Auto IT is most commonly used for handling file uploads and file downloads on websites. To use AutoIT, You need to download and install AutoIT software on our local machines. Download an install of AutoIT is covered in the article. Open Programs – Autoit tool – SciTE Script Editor and add the below mentioned AutoIt script in Autoit editor and save it as ‘ProxyAuthentication.au3’ in your system Compile the file and Convert it as ‘ProxyAuthentication.exe.’ In Eclipse, add the Auto IT file to Selenium Script and run Below is the AutoIT script for HTTP Proxy authentication You need to pass the Auto IT file for execution on Selenium webdriver using the below code Source Code:

Code Explanation:

In the first step, You are initializing an instance of Chrome driver by setting the system property to point the chromedriver.exe file In the second step, You are then initializing an object of web driver and passing the website URL using get method Finally, You are passing username and password to HTTP Proxy authentication popup using an AutoIT script file

Code Output:

Using Alerts

Alerts are simple, inbuilt feature provided by Selenium web driver. You can handle proxy authentication popups using Selenium web driver by switching to the HTTP proxy authentication alert and passing the user name and password directly to the alert. With the help of send keys method. Example: Test Scenario: Handle the HTTP Proxy authentication popup on the website: http://demo.guru99.com/test/basic_auth.php using Alerts in Selenium web driver. Source code Example:

Code Output:

Proxy Authentication done successfully.

Code Explanation:

Initially, You are instantiating an instance of Chrome driver by setting the webdriver property to point the location of chromedriver.exe file Then, You are opening the URL of required website by passing the URL as a parameter to driver.get() method Once URL is opened, You are switching to the username alert and sending the username – guru99. You are then clicking on OK button on the alert using alert.accept method Then, You are switching to the password alert and sending the password – guru99. You are then clicking on OK button on the alert using alert.accept method

Summary

A proxy acts as an intermediary between clients sending requests and server responding. The basic use of a proxy is to maintain privacy and encapsulation between multiple interactive systems. HTTP Proxy authentication with Selenium in Chrome can be handled using the following approaches Passing username and password in the website URL Using the AutoIT tool Using Alerts Of the above three approaches, using alerts is the most effective way to handle HTTP Proxy authentication in Selenium webdriver