Akshata Kulkarni
Akshata Kulkarni

Reputation: 21

How to handle authentication popup with Selenium WebDriver

I am trying to handle authentication popup through my selenium test by passing username and password in URL.

I have tried following solutions:

  1. I have tried to send username and password in URL
  2. I have tried handling with alert, it doesn't work.
  3. I have tried solutions provided in - How to handle authentication popup with Selenium WebDriver using Java, almost all other than AutoIT, none of them worked for me

I have a Maven project, I am trying to send url with username and password from project.properties file, which looks like this -

URL = https://username:password@URL

open url code-

WebDriver driver = new ChromeDriver();

driver.navigate.to(URL);

I get below error in browser console: "there has been a problem with your fetch operation: Failed to execute 'fetch' on 'Window': Request cannot be constructed from a URL that includes credentials"

Upvotes: 0

Views: 788

Answers (1)

Akshata Kulkarni
Akshata Kulkarni

Reputation: 21

I am able to handle this using AutoIT script. The script looks something like this,

WinWaitActive("Sign in")

Sleep(5000)

Send("username")

Send("{TAB}")

Send("password")

Send("{ENTER}")

I run this script through my code,

WebDriver driver = new ChromeDriver();

Runtime.getRuntime().exec("(path)\AutoIt\script.exe");

driver.get(prop.getProperty(URL));

driver.navigate().refresh();

Upvotes: 1

Related Questions