如何通过Java中的Selenium在弹出框中发送用户名和密码?

huangapple go评论101阅读模式
英文:

How to send username and password in popup box through selenium in java?

问题

点击链接查看:弹出截图

我正在尝试使用 Selenium Java 在 Chrome 中自动化访问此链接:http://the-internet.herokuapp.com/basic_auth
我想要输入用户名、密码,然后要么点击登录要么取消。
但是我无法“检查元素”。

英文:

Click the link to see: pop up screenshot

I am trying to automate this:http://the-internet.herokuapp.com/basic_auth in chrome using Selenium java.
I want to insert username, passwors and then either click sign in or cancel.
But I am not able to "inspect element".

答案1

得分: 0

你需要将驱动程序切换到 alert

driver.switchTo().alert().sendKeys("一些文本");

你可能可以发送 tab 键来从用户名框切换到密码框。

英文:

You need to switch the driver over to the alert:

driver.switchTo().alert().sendKeys("Some text");

You might be able to send the tab key to switch from username box to password box.

答案2

得分: 0

这是窗口身份验证弹出窗口,不是JavaScript警报。因此,在这种情况下,您需要修改WebDriver的URL。(AutoIT也可以适用。但以下是处理它的简单方法。)

假设用户名=admin,密码=admin。只需传递以下URL:

driver.get("http://admin:admin@the-internet.herokuapp.com/);
英文:

It is window authentication pop-up, not javascript alert. So, in this case you need to modify Webdriver URL. (AutoIT also can be applicable. But below is the simple way to handle it.)
<br/> say, username=admin, password=admin. Just pass the below URL:

driver.get(&quot;http://admin:admin@the-internet.herokuapp.com/);

huangapple
  • 本文由 发表于 2020年8月31日 00:28:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63659637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定