Search code examples
javatestingautomationautomated-testsselenide

Upload file with selenide webdriver without any input


I am trying to upload file using java selenide automation test.

Place I wrote my test uses upload box without any input value near it.

Upload box is id='file'

I tried to used:

$(By.cssSelector("[id='file']")).uploadFile(new File("myfilePackage" + File.separator + "picture.jpg"))

but that did't help cause there is no input box for file upload.

Then I tried to use:

WebElement elem = getWebDriver().findElement(By.cssSelector("[id='file']"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";

((JavascriptExecutor) getWebDriver()).executeScript(js, elem);
elem.sendKeys("wholePath\\picture.png");

to make the element visible but I get unkown error: canno focus element\n ...

I got it using but this is not what I want:

WebElement elem = getWebDriver().findElement(By.cssSelector("[id='file']"));

((RemoteWebElement) elem ).setFileDetector(new LocalFileDetector());

elem.sendKeys("C:FullPath\\picture.png");

Is there any other way to get file from this kind of upload? I want to upload it from Intellij Package


Solution

  • A solution was very funny - Selenide can't resolve upload in "Evaluate Code Fragment" mode. Basically, my question also answers.