Gaurav Bahadur
Gaurav Bahadur

Reputation: 189

How to enter the credentials in a Javascript pop-up? We can't pass the credentials in the link

Edit: I solved the problem by using "AutoIt". However as Alex said AutoIt is platform dependent I am going to try and implement it.

I have link A, where I need to enter my email Id, it then automatically redirects to link B which has a javascript pop-up which needs email id and password to redirect me to the desired page. This is what I have done till now. I tried passing the credentials in the link A, but it didn't work. Instead of going from link A to link B, I copied link B and passed the credentials along with it. I got server error. I tried using sikuli pattern and screen class, but It said "error path cannot be found" for which I tried looking for the solution but couldn't as it got deprecated or something.

here is my code

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://linkA.com");
driver.findElement(By.xpath("//*[@id=\"uemail\"]")).sendKeys("[email protected]");
driver.findElement(By.xpath("//*[@id=\"button\"]/div[2]/button")).click();

After this code I am redirected to link B, where the javascript popup actually is.Till here everything is fine.

Instead of last 3 lines I tried these things.

driver.get("https://emailID:[email protected]");

And

driver.get("https://emailID:[email protected]");

Upvotes: 0

Views: 322

Answers (1)

Alexey R.
Alexey R.

Reputation: 8676

I believe the latter is not JavaScript pop-up but basic authorization pop-up that is not under control of web driver. You need to set up a proxy that would add Authorization header to your requests, and assign your username:password pair encoded in Base64.

Here are some detail on how to apply Browsermob Proxy library to address Basic auth issue.

What you have tried so far is actually deprecated due to security reasons and no more supported is the majority of modern browsers.

Upvotes: 1

Related Questions