在写文件上传脚本的时候,遇到了很多问题,包括元素定位,以及上传操作,现在总结下来以下几点:

1. 上传的控件定位要准确,必要时要进行等待

 WebElement adFileUpload = driver.findElement(By.xpath("//input[@type='file']"));

2. 上传操作

String filePath ="D:\\taxonomy\\DB\\HaierTaxonomy.xlsx";
    adFileUpload.sendKeys(filePath);
    try {
     Thread.sleep(10000);
     } catch (InterruptedException e) {
     e.printStackTrace();
     }
    driver.findElement(By.xpath("//button[@class='btn btn-primary start'][@type='button']")).click();
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//input[@id='complete-template-upload'][@type='button']")).click();

3. 如上脚本,文件的路径一定要准确,否则即使脚本不出错,文件仍旧上传失败。

相关文章:

  • 2021-11-19
  • 2021-11-04
  • 2022-03-07
  • 2021-08-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-10-01
  • 2021-08-22
  • 2021-05-04
  • 2021-06-08
相关资源
相似解决方案