简体   繁体   English

如何使用Selenium 2.0(WebDriver)处理Windows弹出窗口?

[英]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对话框alertconfirmprompt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium Firefox WebDriver处理多个弹出窗口 - How to handle multiple pop-ups with selenium firefox webdriver 如何处理硒webdriver中具有空白ID的弹出窗口? - How to handle pop up windows with blank id in selenium webdriver? 如何处理linkedIn授权使用Java在Selenium Webdriver中弹出? - How to Handle linkedIn authorization Pop up in selenium webdriver using Java? 如何使用Java处理Selenium WebDriver中的弹出窗口 - How to handle Pop-up in Selenium WebDriver using Java 无法使用 Robot 类处理 Windows 10 弹出窗口 - Unable to handle Windows 10 pop-ups using Robot class 如何使用Java切换到Jquery Pops Inselenium WebDriver - How to switch to Jquery pop ups inselenium webdriver using java 通过Selenium Webdriver(3.x)处理自定义弹出窗口(不是默认窗口) - Handling custom pop-ups (not the default windows one) through selenium webdriver (3.x) 如何使用 Selenium WebDriver 处理 Windows 文件上传? - How to handle windows file upload using Selenium WebDriver? 如何处理弹出 windows Java Selenium? - How to handle pop up windows Java Selenium? 如何使用JAVA在Selenium Webdriver的Internet Explorer中处理服务器身份验证弹出窗口? - How can i handle Server authentication pop-up in Internet Explorer in Selenium Webdriver using JAVA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM