2016-04-22 36 views
0

我想上傳一個文件使用硒發送鍵,但不工作,在我的情況下按鈕名稱是附加簽名關閉,它不工作。請幫助硒發送鍵上傳按鈕不工作

<form class="v-upload v-widget v-upload-immediate" enctype="multipart/form-data" method="post" action="https://gbl04115.systems.uk.hsbc:8571/DSLWeb/APP/UPLOAD/2/921/action/3305f203-9e0c-4213-aecd-6ee2b2b29eb1" target="921_TGT_FRAME"> 
 
<div aria-describedby="gwt-uid-2"> 
 
<input type="hidden"/> 
 
<input class="gwt-FileUpload" type="file" name="921_file" aria-describedby="gwt-uid-2"/> 
 
<div class="v-button" tabindex="0" role="button" aria-hidden="false" aria-describedby="gwt-uid-2"> 
 
<span class="v-button-wrap"> 
 
<span class="v-button-caption">Attach Sign-off</span> 
 
</span>

+0

嗨@AutoMater其中是您的按鈕ID和上傳您的代碼的名稱。 –

+0

對不起,我沒有得到你 –

+0

我的意思是我如何得到你的按鈕元素ID或名稱。例如。 –

回答

0

試試這個,讓我知道,如果它不工作

WebElement fileInput = driver.findElement(By.className("gwt-FileUpload")); 
fileInput.sendKeys("C:/path/to/file.jpg"); 
+0

列表 elements = driver.findElements(By.className(「gwt-FileUpload」)); elements.get(1).sendKeys(AbsolutePath); 使用上述代碼工作 –

0

我希望這個答案將有助於解決您的問題。但我還沒有測試過。

WebElement fileInput = driver.findElement(By.name("uploadfile")); 
fileInput.sendKeys("C:/path/to/file.jpg"); 


    (OR) 

driver.findElement(By.id("inputFile")).sendKeys("C:/path/to/file.jpg"); 
+0

它不起作用。 –

0

@AutoMater - 您可以更新如下代碼:

,因爲它是爲我工作它應該工作。並根據您的要求給您的測試方法優先。舉例來說,我在這裏將@Test(優先級= 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

List elements = driver.findElements(By.className(「gwt-FileUpload」)); elements.get(1).sendKeys(filePath);

它使用上面的代碼。 謝謝@Andersson