Having an issue trying to upload a file via php unit through selenium. This is the code for my current attempt.

  public function testFileUpload() 
     $filePath = '/Users/cdolan/Desktop/CamsodaTest/mern.png';
     $file_input = $this->webDriver->findElement(WebDriverBy::cssSelector('#upload-button'))->click();
     $file_input->setFileDetector(new LocalFileDetector());

The test seems to run and complete with no errors, however it will not upload a file! It seems to get stuck on this screen and then closes out without uploading anything.

Upload box

Any advice would be appreciated.

  • 1
    Just an observation, can Selenium interact with a non-browser window? You may need to use a different module to interact with a non-browser window.
    – Yu Zhang
    Jun 26, 2017 at 22:10
  • I was trouble shooting with a co-worker and he said exactly what you said, but i was hoping there would be a work around.. I was successful in using the robot class for java however for php I don't think that would work.
    – Christian
    Jun 26, 2017 at 22:12

1 Answer 1


Selenium can not interact with non-browser elements, hence you need to use third party tools. In Windows the simplest would be using AutoIT automation tool with which you can create scripts for windows-based-applications interactions and then execute those scripts from your code. There should be something similar for MacOS as well, but you'll have to google that on your own.

I'm not giving any examples with AutoIT as on how to implement this because you're using Mac and this implementation is very basic and straightforward. Just giving you a direction on where to do your search from this point.

Not the answer you're looking for? Browse other questions tagged or ask your own question.