[英]Handle save as dialog box by selenium web driver in java
I'm Trying to save a Html Page using Selenium script in java which perform following operations 我正在尝试使用Java中的Selenium脚本保存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中下载的默认选项,但是当我运行脚本时,它会不断显示我弹出窗口,我需要的是:-
Robot
class in java might help you. Java中的
Robot
类可能会对您有所帮助。 Check this link as well. 还要检查此链接 。
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);
Accepting confirmation popups in Selenium can be handled via Alert
object (assuming driver instance is ready): 可以通过
Alert
对象处理Selenium中接受确认弹出窗口(假设驱动程序实例已准备就绪):
Alert myAlert = driver.switchTo().alert();
myAlert.accept();
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 不要忘记在实际执行步骤之前而不是在执行步骤之前放置代码
Please switch to windows dialogs first using get window handles eg. 请首先使用获取窗口句柄切换到Windows对话框。 Save As
另存为
Then, use Robot commands to send Enter key. 然后,使用机器人命令发送Enter键。 It will save the file.
它将保存文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.