[英]How to handle windows pop ups using selenium 2.0 (webdriver)?
enter code here
Brief : I am currently using selenium 2.0 to automate the testing of an UI.Everything was fine till yesterday till i came across pop ups.I am having to handle windows popups. enter code here
简介:我目前正在使用selenium 2.0来自动化UI的测试。直到昨天,一切都还好,直到我遇到弹出窗口。我必须处理Windows弹出窗口。
The problem : I am navigating to page using the following code => 问题:我使用以下代码导航到页面=>
driver.get("http://xxx.xx.x.xxx:zzzz/yyyy/");
driver.findElement(By.name("username")).sendKeys("username");
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.className("rowClass")).submit();
driver.findElement(By.name("uploadfile")).click(); //this is the browse button
Now the problem arises when i click the browse button.It opens up another windows browse file window.What i need to do is to select a file by navigating to the given path and then select a particular file and i am not able to do the same currently.What could be the suggestion.Some one said it was not possible to do the same using selenium 2.0 and to use autoit instead.if someone knows how to do it please let me know else please suggest a better way to get it done.Thanks and regards. 现在,当我单击浏览按钮时出现了问题。它打开了另一个Windows浏览文件窗口。我需要做的是通过导航到给定的路径来选择一个文件,然后选择一个特定的文件,但我无法执行有人说不可能使用selenium 2.0和autoit来做同样的事情。如果有人知道怎么做,请让我知道,否则请提出一种更好的方法来完成它。谢谢并恭祝安康。
PS : PS:
//this is mentioned as the solution in http://seleniumhq.org/docs/03_webdriver.htmlbut did not work in my case //这在http://seleniumhq.org/docs/03_webdriver.html中作为解决方案提及,但在我的情况下不起作用
Alert alert = driver.switchTo().alert();
This is more of a "How to upload a file in WebDriver?" 这更多是“如何在WebDriver中上传文件?” question which has been asked many times :). 这个问题已经问了很多遍了 :)。
Selenium 2 (WebDriver) Java example: Selenium 2(WebDriver)Java示例:
// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.name("uploadfile"));
fileInput.sendKeys("C:/path/to/file.jpg");
The idea is to directly send the absolute path of the file to an element which you would usually click at to get the modal window - that is <input type='file' />
element (or the Browse
button as you call it). 想法是将文件的绝对路径直接发送到通常会单击以获取模式窗口的元素-即<input type='file' />
元素(或调用时的“ Browse
按钮)。
Also, the Alert
interface is just for popup JavaScript dialogs - alert
, confirm
, prompt
. 另外, Alert
界面仅用于弹出JavaScript对话框alert
, confirm
, prompt
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.