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

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

    如下:

     1 package com.test.upload;
     2 
     3 import java.io.File;
     4 
     5 import org.openqa.selenium.By;
     6 import org.openqa.selenium.WebDriver;
     7 import org.openqa.selenium.firefox.FirefoxDriver;
     8 
     9 public class UploadTest {
    10 
    11     public static void main(String[] args) {
    12         WebDriver driver = new FirefoxDriver();
    13         driver.get("file:///D:/10-selenium/workspace/SeleniumTest/src/com/test/upload/upload.html");
    14         driver.manage().window().maximize();
    15 
    16         String path = System.getProperty("user.dir") + "\src\com\test\upload\upload.html";
    17         System.out.println(path);
    18         File file = new File(path);
    19 
    20         if (file.exists()) {
    21             //找到input,然后利用sendKeys来上传文件
    22             driver.findElement(By.cssSelector("#uploadFIle")).sendKeys(file.getPath());
    23             System.out.println(file.getPath());
    24         }
    25 
    26         driver.quit();
    27     }
    28 
    29 }

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

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

    使用方法参考:

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

    工具下载地址:

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

  • 相关阅读:
    R语言 which() 、 which.min() 、 which.max() 函数
    R rep() 函数
    R语言 一个向量的值分派给另一个向量
    R语言 sample抽样函数
    超参数 hyperparameters
    随机游走模型(Random Walk)
    随机数
    Lambda 函数与表达式
    static
    变量的申明定义
  • 原文地址:https://www.cnblogs.com/moonpool/p/5675970.html
Copyright © 2011-2022 走看看