简体   繁体   English

如何使用VBA上传文件(输入文件)

[英]How to upload a file using VBA (input file)

I have this CSV file that it need to be uploaded in a WebSite , but this website have an input type file. 我有此CSV文件,需要将其上传到WebSite,但此网站有一个输入类型文件。

I know its pretty impossible because i spent like three weeks loking for an answer,i found another way to upload the file WITHOUT USING THE INPUT TYPE FILE* so i was wondering if anyone found a solution to my probleme 我知道这几乎是不可能的,因为我花了大约三周时间寻找答案,我找到了另一种无需使用输入类型文件*即可上传文件的方式,所以我想知道是否有人找到了解决我问题的方法

This is what i have : 这就是我所拥有的:

This is my firt attempt like any average personne using VBA : 这是我的尝试,就像任何使用VBA的普通人一样:

  Set UploadCSV = IEDoc.getElementById("namecsv") 
  UploadCSV.Value = "something\toto.csv" 

This is my input type file: 这是我的输入类型文件:

    <input name="filename" class="text align_center" id="nomfichiercsv" type="file" size="24" accept="text/html,text/plain" value=""/> 

Thank's 谢谢


I tried the SendKeys function no luck 我尝试了SendKeys函数没有运气

Like mentioned you can do this in an Eclipse project using the Java Selenium driver. 如前所述,您可以使用Java Selenium驱动程序在Eclipse项目中执行此操作。 Afterwards part of the code could look like this; 之后,部分代码可能如下所示;

driver.findElement(By.id("nomfichiercsv")).sendKeys(UploadCSV);
driver.findElement(By.id("submit")).click();

In VBA, you can use the below code after you have identified the element: 在VBA中,您可以在确定元素后使用以下代码:

driver.FindElementById("Id of the element").SendKeys ("path to the input file")

If the frame changes when you are trying to upload the file, you will need to switch to the new frame. 如果在尝试上传文件时框架发生变化,则需要切换到新框架。 If Id is not present for the element, use other Web Element selector methods. 如果该元素不存在ID,请使用其他Web元素选择器方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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