0

In selenium + Java I am using webElement.sendKeys(filePath) to upload the file in the webpage in jenkins which is causing intermittently InvalidArgumentException exception though file is there. File is located in the source code repo in resources folder ;

org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : 
/blah/blah1/abc.pdf
 (Session info: headless chrome=88.0.4324.96)

    if (driver instanceof RemoteWebDriver) {
        ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
    }
    assertThat(file.exists()).isTrue();
    webElement.sendKeys(file.getAbsolutePath());

Here sendKeys intermittently giving InvalidArgumentException though assertion is passing always.

Anyone has encountered similar problems? Any solution please. Details about linux docker container

os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-1103-azure', java.version: 
'11.0.5'
chrome: {chromedriverVersion: 91.0.4472.19 
selenium.version :- 3.141.59
asinha
  • 337
  • 1
  • 6
  • 24
  • 1
    maybe check the answer here: https://stackoverflow.com/questions/62595459/how-to-upload-a-file-by-transfering-the-file-from-the-local-machine-to-the-remot (Looks like you may want to set the file detector on the remote element?) – pcalkins Jun 16 '21 at 18:27
  • I am already setting the remote file detector as part of code snippet else it would fail always. `((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());` Still its failing intermittently giving InvalidArgumentException – asinha Jun 17 '21 at 08:15
  • Any solution please – asinha Jun 17 '21 at 14:17
  • try setting it on the webelement... if this is random, though... I'd check things like file space in your container... (the file is transferred to your remote machine... then that path is put into the input) – pcalkins Jun 17 '21 at 16:59
  • 1
    I found the problem thanks. While we running our test in docker container , some other containers were getting started by different projects .so this problem was happening – asinha Jun 18 '21 at 11:50

0 Answers0