java 在java中通过selenium web驱动程序处理另存为对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25763472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:38:29  来源:igfitidea点击:

Handle save as dialog box by selenium web driver in java

javaseleniumselenium-webdriverautomationwebdriver

提问by Deepak gupta

I'm Trying to save a Html Page using Selenium script in java which perform following operations

我正在尝试使用执行以下操作的 Java 中的 Selenium 脚本保存 Html 页面

  1. open the web page.
  2. fire a right click event.
  3. click on save as html option.
  1. 打开网页。
  2. 触发右键单击事件。
  3. 单击另存为 html 选项。

Now problem is when script click on save as html option it shows a pop-up to save html.

现在的问题是当脚本点击另存为 html 选项时,它会显示一个弹出窗口来保存 html。

I already set default option for download in Firefox but when i run the script it keep showing me pop-up again and again what i need is:-

我已经在 Firefox 中设置了默认下载选项,但是当我运行脚本时,它不断向我显示弹出窗口,我需要的是:-

  1. when Firefox shows a save as dialog box then it'll fire an enter event so that it can save html by using Selenium script.
  1. 当 Firefox 显示另存为对话框时,它会触发一个 enter 事件,以便它可以使用 Selenium 脚本保存 html。

回答by Luffy

Robotclass in java might help you. Check this linkas well.

Robotjava中的类可能会帮助你。也检查这个链接

Here is a sample code:

这是一个示例代码:

// Create object of Robot class<br>
Robot object=new Robot();

// Press Enter<br>
object.keyPress(KeyEvent.VK_ENTER);

// Release Enter<br>
object.keyRelease(KeyEvent.VK_ENTER);

回答by mfsi_krushnas

Window pop ups cant be handled by Selenium.So you can go for follwing options : -

Selenium 无法处理窗口弹出窗口。因此您可以选择以下选项:-

(1) Java Robot Class

(1) Java机器人类

(2) Sikuli[Recommended]

(2)斯库里【推荐】

(3) AutoIt

(3) AutoIt

These are 3rd party tools used to handle window based pop ups.

这些是用于处理基于窗口的弹出窗口的第 3 方工具。

回答by German Petrov

Accepting confirmation popups in Selenium can be handled via Alertobject (assuming driver instance is ready):

在 Selenium 中接受确认弹出窗口可以通过Alert对象处理(假设驱动程序实例已准备好):

Alert myAlert = driver.switchTo().alert();
myAlert.accept();

回答by bansal shah

Use autoit download the autoit exe record clicking of that button Use the code and execute it via JS executor

使用autoit下载autoit exe记录点击那个按钮使用代码通过JS执行器执行

Dont forget to place the code before you are actually executing the step not after executing it

不要忘记在实际执行步骤之前而不是在执行之后放置代码

回答by Bharat

Please switch to windows dialogs first using get window handles eg. Save As

请首先使用获取窗口句柄切换到 Windows 对话框,例如。另存为

Then, use Robot commands to send Enter key. It will save the file.

然后,使用 Robot 命令发送 Enter 键。它将保存文件。