2016-04-22 51 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