0

I'm writing an automation script for one project, there's a task where I need to upload a file from a local driver to the browser. So can someone please help me out!

Image Description Here

1

2 Answers 2

1

According to your image I can see, there is only one file. testexcel.xlxs. So what you can do is you can specify the file path. You haven't posted the HTML Code and the Programming Language that you are trying to implement this. The following code snippet is written in Java just to take an idea.

    // Get the input field id
    WebElement uploadElement = driver.findElement(By.id("uploadfile"));

    // Enter the file path onto the file-selection input field
    uploadElement.sendKeys("H:\\Excelfile\\testexcel.xlxs");

    // Click the "SUBMIT" button
    driver.findElement(By.name("submit")).click();
Sign up to request clarification or add additional context in comments.

Comments

0

Sendkeys is one of method to upload file and another method.

Robot Class in a separate class which is part of Java not a part of Selenium, Robot class is mainly created for automating Java Platform implementation. The primary purpose of Robot is to facilitate automated testing of Java platform implementations. In simple terms, the class provides control over the mouse and keyboard devices.

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);

for more information go through this link.

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/

check this answer https://stackoverflow.com/a/56168803/4513879

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.