2016-05-04 32 views
0

2つの画像(.png)ファイルをアップロードしたい。ファイルをアップロードするためにアクションキーと送信キーを使用しました.1つのファイルで正常に動作していますが、ファイルがアップロードされていません。Seleniumでファイルをアップロードする

Actions action1 = new Actions(m.driver); 
action1.moveToElement(m.driver.findElement(By.id("onetidIOFile"))).click(); 
WebElement s=m.driver.findElement(By.xpath("//input[@type='file']")); 
s.sendKeys("path of one file");m.click("xpath", ".//[@id='attachOKbutton']"); 
m.click("id", "Ribbon.ListForm.Edit.Actions.AttachFile-Large"); 
action1.moveToElement(m.drive‌​r.findElement(By.id("onetidIOFile"))).click(); 
m.driver.findElement(By.xpath("//‌​input[@type='file']")).sendKeys("path of second file "); 
m.key("Enter","attachOKbutton"); 

誰でもこの操作を手伝ってもらえますか?

+1

あなたのコードとHTMLを追加します。 – Guy

+2

コードをコメントとして貼り付けないでください。代わりに質問を編集してください – Szeki

+0

はコードを追加しました。 – sajju

答えて

0

@sajju - あなたは以下のようにコードを更新することができます。

を、それは私のために働いているとそれが動作するはずです。また、必要に応じてテスト方法を優先します。例として、ここでは@Test(priority = 1)として優先順位を付けました。私はそれがあなたのために働くことを望む。

@Test(priority = 1) 
    public void CERTIFICATIONSSCREENUploadCertficationFilesValidation() 
      throws InterruptedException, AWTException { 

     //Click on File Upload Button 
     driver.findElement(By.xpath("//*[@id='certificationFile']")).click(); 
     Thread.sleep(1000); 
     // Set the file name in the clipboard. Also following line of code will search file in your computer so make sure you provide correct file path. 

     StringSelection s = new StringSelection("C:\\Doc\\CertificationFile.xls"); 
     Toolkit.getDefaultToolkit().getSystemClipboard().setContents(s, null); 
     Thread.sleep(1000); 

     Robot robot1 = new Robot(); 
     robot1.keyPress(KeyEvent.VK_ENTER); 
     robot1.keyRelease(KeyEvent.VK_ENTER); 
     robot1.keyPress(KeyEvent.VK_CONTROL); 
     robot1.keyPress(KeyEvent.VK_V); 
     robot1.keyRelease(KeyEvent.VK_V); 
     robot1.keyRelease(KeyEvent.VK_CONTROL); 
     robot1.keyPress(KeyEvent.VK_ENTER); 
     robot1.keyRelease(KeyEvent.VK_ENTER); 
     Thread.sleep(1000); 

}

+0

私はこのコードを試しました。 – sajju

関連する問題