Posts

How To Access Basic Auth with Selenium

The Problem Sometimes you'll work with applications that are secured behind  Basic HTTP Authentication  ( Basic Auth). In order to access them you'll need to pass credentials to the site when requesting a page. Otherwise you'll get a system level pop-up prompting you for a username and password -- rendering Selenium helpless. Before Selenium 2 we were able to accomplish this by injecting credentials into a custom header. But now the cool kid way to do it it was something like  BrowserMob Proxy . Some people are solving this with browser specific configurations too. But all of this feels heavy. Instead, let's look at a simple approach that is browser agnostic and quick to setup. A Solution By specifying the username and password  in the URL  when visiting a page with Selenium, we can a side-step the system level dialog box from Basic Auth and avoid the need to set up a proxy server. This approach will work for both HTTP or HTTPS pages. Let's take a look

Find out broken links / images on website using webDriver

Broker Links:  By just seeing the Links in the UI, we may not be able to confirm if that link is working or not until we click and verify it. To achieve this, we can use HttpClient library to check status codes of the URLs on a page. If request was NOT processed correctly, then the HTTP status codes may not return 200 status code. We can easily say whether the link is broken or not with status codes. Now let us jump into the example, First we will try to find all anchor tags on the page by using Webdriver. By using the below syntax: We need to iterate through each link and verify request response Status codes and it should be 200 if not, we will increment invalid links count Let us look into the example : package com.linked; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.openqa