File not uploaded using Remote WebElement

34 Views Asked by At

I am trying to automate this fileupload using remoteWebElement since I have already uploaded using Actions class. However, I am getting some exception. Can someone please help?

 package uploadFiles;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebElement;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class UsingRemoteWebElement {
    //works only with Selenium 3
    
    WebDriver driver;
    String url = "https://the-internet.herokuapp.com/upload";
    By browseButton = By.id("file-upload");
    By uploadButton = By.id("file-submit");

    @BeforeTest
    public void setUp() {
        // WebDriverManager.chromedriver().setup();
        driver = new EdgeDriver();
        driver.manage().window().maximize();
        driver.get(url);
    }

    @Test
    public void uploadFile() throws InterruptedException {
        WebElement browseElement = driver.findElement(browseButton);
        ((RemoteWebElement) browseElement).setFileDetector(new LocalFileDetector());

        browseElement.sendKeys("C:\\Users\\ACER\\Desktop\\test.au3");
        Thread.sleep(5000);
    }

    @AfterTest
    public void tearDown() {
        driver.quit();
    }
}

Exception: FAILED: uploadFiles.UsingRemoteWebElement.uploadFile org.openqa.selenium.UnsupportedCommandException: unknown command: unknown command: session/5b100d5ec97bfa73b7f0292ae4b3c57c/se/file Build info: version: '4.10.0', revision: 'c14d967899'

0

There are 0 best solutions below