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

  • 相关阅读:
    C#概述
    作为一个程序员小小感悟!!
    c# 合并两个DataTable
    C# FastReport .NET打印
    c# System.Net.Sockets =》TcpListener用法
    开博第一章
    Vue 报错 Uncaught (in promise)
    ASP.NET MVC 中的过滤器
    SpringBoot 打包成war
    SprintBoot 实现上传下载
  • 原文地址:https://www.cnblogs.com/moonpool/p/5675970.html
Copyright © 2011-2022 走看看