
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
HTTP Basic Authentication with Password in URL
We can do HTTP basic authentication URL with @ in password. We have to pass the credentials appended with the URL. The username and password must be added with the format − https://username:password@URL.
Let us make an attempt to handle the below browser authentication.
Once the User Name and Password are entered correctly and the OK button is clicked, we should be navigated to the actual page with the text Congratulations! You must have the proper credentials.
Syntax
https://username:password@URL https://admin:[email protected]/basic_auth
Here, the username and password value is admin.
URL is www.the-internet.herokuapp.com/basic_auth
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class BrwAuthnPopup{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String a = "admin"; // appending username, password with URL String s = "https://" + a + ":" + a + "@" + "the-internet.herokuapp.com/basic_auth"; driver.get(s); // identify text String m = driver.findElement(By.cssSelector("p")).getText(); System.out.println("Text is: " + m); driver.close(); } }
Output
Advertisements