
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How can we handle authentication popup in Selenium WebDriver using Java?
We can handle authentication popup in Selenium webdriver using Java. To do this, we have to pass the user credentials within the URL. We shall have to add the username and password to the URL.
Syntax −
https://username:password@URL https://admin:admin@the-internet.herokuapp.com/basic_auth Here, the admin is the username and password. URL – www.the-internet.herokuapp.com/basic_auth Let us work and accept the below authentication popup.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class AuthnPopup{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String u = "admin"; // adding username, password with URL String str = "https://" + u + ":" + u + "@" + "the-internet.herokuapp.com/basic_auth"; driver.get(str); // identify and get text after authentication of popup String t = driver.findElement(By.cssSelector("p")).getText(); System.out.println("Text is: " + t); //close browser driver.close(); } }
Output
- Related Articles
- How to handle authentication popup with Selenium WebDriver using Java?
- How to handle frame in Selenium WebDriver using java?
- What is the best way to handle a Javascript popup using Selenium Webdriver?
- How can I handle multiple keyboard keys using Selenium Webdriver?
- How to handle popup windows in Selenium?
- How to click Allow on Show Notifications popup using Selenium Webdriver?
- How to handle windows file upload using Selenium WebDriver?
- How to handle SSL certificate error using Selenium WebDriver?
- What are the different ways of handling authentication popup window using Selenium?
- How to handle frames in Selenium Webdriver in Python?
- How does Selenium Webdriver handle SSL certificate in Firefox?
- How does Selenium Webdriver handle SSL certificate in Chrome?
- Handle Firefox Not Responding While Using Selenium WebDriver With Python?
- How does Selenium Webdriver handle the SSL certificate in Safari?
- How does Selenium Webdriver handle the SSL certificate in Edge?

Advertisements