Selenium: Upload file in Google Chrome

后端 未结 3 1250
抹茶落季
抹茶落季 2021-01-05 00:42

Is there any way to upload file in Google Chrome since Selenium RC \"attach_file\" only supports *Firefox? Any suggestion or workarounds are much appreciated.

3条回答
  •  囚心锁ツ
    2021-01-05 01:16

    If you are using Webdriver then to upload file all you need is use "sendKeys" to type the file path. You need to 'skip' the part of clicking on the browse button that opens a dialog box to select the file. A Java version that works for me looks something like below,

    WebElement inputFilePath = driver.findElement(By.id("filepath"));
    inputFilePath.sendKeys("/absolute/path/to/my/local/file");
    

提交回复
热议问题