zoukankan      html  css  js  c++  java
  • selenium测试(Java)--上传文件(十五)

    1. 当页面中是通过input标签实现上传功能时,可以使用selenium来上传功能。

    如下:

    package com.test.upload;
    
    import java.io.File;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class UploadTest {
    
        public static void main(String[] args) {
            WebDriver driver = new FirefoxDriver();
            driver.get("file:///D:/10-selenium/workspace/SeleniumTest/src/com/test/upload/upload.html");
            driver.manage().window().maximize();
    
            String path = System.getProperty("user.dir") + "\src\com\test\upload\upload.html";
            System.out.println(path);
            File file = new File(path);
    
            if (file.exists()) {
                //找到input,然后利用sendKeys来上传文件
                driver.findElement(By.cssSelector("#uploadFIle")).sendKeys(file.getPath());
                System.out.println(file.getPath());
            }
    
            driver.quit();
        }
    
    }

    2. 如果网页中的上传功能不是使用input来实现,那就需要使用其他方法来实现模拟

    可以使用AutoIt录制脚本实现:

    使用方法参考:

    http://www.cnblogs.com/fnng/p/4188162.html

    工具下载地址:

    官网:https://www.autoitscript.com/site/autoit/downloads/
    网盘:http://pan.baidu.com/s/1cievQe

  • 相关阅读:
    The 2019 China Collegiate Programming Contest Harbin Site A
    牛客练习赛15
    Wannafly挑战赛13-C
    Wannafly挑战赛13-D
    Subsequence Counting
    Minimize the error
    Educational Codeforces Round 42 (Rated for Div. 2)
    K-th Number
    Wannafly挑战赛13-E
    Minimum spanning tree for each edge
  • 原文地址:https://www.cnblogs.com/xinxin1994/p/7289578.html
Copyright © 2011-2022 走看看