如何在Javascript弹出窗口中输入凭据?我们无法通过链接中的凭据 [英] How to enter the credentials in a Javascript pop-up? We can't pass the credentials in the link

查看:126
本文介绍了如何在Javascript弹出窗口中输入凭据?我们无法通过链接中的凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用" AutoIt "解决了该问题.但是,正如Alex所说的,AutoIt依赖于平台,我将尝试实现它.

我有链接A,我需要在其中输入我的电子邮件ID,然后它自动重定向到链接B,该链接B具有一个JavaScript弹出窗口,该弹出窗口需要电子邮件ID和密码将我重定向到所需页面.这是我到目前为止所做的. 我尝试在链接A中传递凭据,但没有成功. 我没有从链接A转到链接B,而是复制了链接B并随其一起传递了凭据.我收到服务器错误. 我尝试使用sikuli模式和屏幕类,但是它说找不到错误路径",为此我尝试寻找解决方案,但由于过时或其他原因而无法解决.

这是我的代码

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();

在这段代码之后,我被重定向到链接B,实际上是javascript弹出窗口,直到这里一切都很好.

我尝试了这些东西,而不是最后三行.

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

还有

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

解决方案

我相信后者不是JavaScript弹出窗口,而是不受Web驱动程序控制的基本授权弹出窗口.您需要设置一个代理,该代理将在请求中添加Authorization标头,并分配以Base64编码的username:password对.

有关如何应用Browsermob代理库来解决基本身份验证问题的一些详细信息.. >

由于安全原因,到目前为止,您尝试过的操作实际上已过时,大多数现代浏览器都不再支持.

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");

解决方案

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.

这篇关于如何在Javascript弹出窗口中输入凭据?我们无法通过链接中的凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆