1

enter code hereBrief : 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.

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.

PS :

//this is mentioned as the solution in http://seleniumhq.org/docs/03_webdriver.htmlbut did not work in my case

Alert alert = driver.switchTo().alert(); 
4

1 に答える 1

0

これは、「WebDriver でファイルをアップロードする方法」のようなものです。何度も尋ねられた質問:)。

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");

アイデアは、ファイルの絶対パスを、通常はクリックしてモーダルウィンドウを取得する要素に直接送信することです-それは<input type='file' />要素(またはBrowseあなたがそれを呼び出すボタン)です。

また、Alertインターフェイスはポップアップ JavaScript ダイアログ用です - alert, confirm, prompt.

于 2012-05-24T08:12:16.487 に答える