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

此生再无相见时 提交于 2020-01-16 12:00:29

问题


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("emailID@email.com");
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:password@linkA.com");

And

driver.get("https://emailID:password@linkB.com");

回答1:


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.



来源:https://stackoverflow.com/questions/59194474/how-to-enter-the-credentials-in-a-javascript-pop-up-we-cant-pass-the-credentia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!