How to upload file in selenium-ide 3-7-4

拟墨画扇 提交于 2019-11-28 14:50:03

1) Using sendkeys we can send file path name:-

It’s the most basic technique to perform the upload of a file.Get the file upload element either by using the Id or Name. And call the Webdriver’s sendKeys() method to set the value of the file to upload.

Remember following two things when uploading files in WebDriver

1)There is no need to simulate the clicking of the "Browse" button. WebDriver automatically enters the file path onto the file-selection text box of the <input type="file"> element.

2)When setting the file path in your Java IDE, use the proper escape character for the back-slash.

Try this:-

     WebDriver driver = new FirefoxDriver();

     // Put an Implicit wait, 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

     // Launch the URL
     driver.get("http://toolsqa.com/automation-practice-form");

     WebElement element = driver.findElement(By.id("photo"));

     element.sendKeys("/home/savera9/Desktop/test.jpg");

There is another techniques also for uploading file please check this

2) Using Robot Class:-

    driver.findElement(By.xpath("Path of that element")).click();

    StringSelection strSel = new StringSelection("upload file path");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strSel, null);


    Robot robot = new Robot();

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    Thread.sleep(3000);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);

3) Using AutoIT:-

AutoIT helps to upload files by transferring the control from Selenium web driver to AutoIT. We need to explicitly call the AutoIT script from our program. After clicking on upload button, the focus will be moved to AutoIT and it will execute the statements which will be used to upload files.

4) Using Sikuli:-

Sikuli is an open source Graphical User Interface automation tool. Sikuli will be used to automate anything that you can view on the screen. It uses image recognition to speak with the GUI elements. When there is no easy access to a GUI’s source code this is one of the best ways to get the appropriate response.

There is another ways also to upload file go through this link https://www.evoketechnologies.com/blog/selenium-automation-uploading-multiple-files-via-web-browsers-file-dialog/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!