简体   繁体   中英

Using selenium webdriver to upload a file

I'm trying to build some automated test for a mailbox application and I'm trying to attach a file. I've read all the documentation from previous post and was able to come up with this:

public void I_attach_a_file_that_exceeds_the_limit() throws Throwable {

    WebElement attachFile = driver.findElement(By.id("attachment"));
    File f = new File("C:\\coop-provider-swm-specs\\src\\test\\resources\\attachments\\20481kb.txt");
    attachFile.sendKeys(f.getCanonicalPath());

}

The problem with this is that the file that it attaches is not the real file. The file that is attached is blank (not sure how that works). The file that I need to attach is a big file and I need to do this in order the authenticate that the user does not exceed the limit for attachments that is allowed.

Change:

attachFile.sendKeys(f.getCanonicalPath());

To:

attachFile.sendKeys(f.getCanonicalPath()).submit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM