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
Handle save as dialog box by selenium web driver in java
提问by Deepak gupta
I'm Trying to save a Html Page using Selenium script in java which perform following operations
我正在尝试使用执行以下操作的 Java 中的 Selenium 脚本保存 Html 页面
- open the web page.
- fire a right click event.
- click on save as html option.
- 打开网页。
- 触发右键单击事件。
- 单击另存为 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 中设置了默认下载选项,但是当我运行脚本时,它不断向我显示弹出窗口,我需要的是:-
- 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.
- 当 Firefox 显示另存为对话框时,它会触发一个 enter 事件,以便它可以使用 Selenium 脚本保存 html。
回答by Luffy
回答by mfsi_krushnas
回答by German Petrov
Accepting confirmation popups in Selenium can be handled via Alert
object (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 键。它将保存文件。