One solution for File Upload using Java Robot API with Selenium WebDriver by Java

后端 未结 4 1885
你的背包
你的背包 2020-11-29 00:45

I saw that lots of people have Problems uploading a file in a test Environment with Selenium WebDriver. I use the selenium WebDriver and java, and had the same problem. I fi

4条回答
  •  时光取名叫无心
    2020-11-29 01:24

    Actually, there is an in-built technique for this, too. It should work in all browsers and operating systems.

    Selenium 2 (WebDriver) Java example:

    // assuming driver is a healthy WebDriver instance
    WebElement fileInput = driver.findElement(By.xpath("//input[@type='file']"));
    fileInput.sendKeys("C:/path/to/file.jpg");
    

    The idea is to directly send the absolute path to the file to an element which you would usually click at to get the modal window - that is element.

提交回复
热议问题