1

This question already has an answer here:

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';
     $this->flingLogIn();
     $this->webDriver->findElement(WebDriverBy::cssSelector('.btn.btn-upgrade-nav.no-follow'))->click(); 
     $this->webDriver->findElement(WebDriverBy::cssSelector('.add-pic'))->click();
     sleep(3);
     $file_input = $this->webDriver->findElement(WebDriverBy::cssSelector('#upload-button'))->click();
     $file_input->setFileDetector(new LocalFileDetector());
     $file_input->sendKeys($filePath)->submit();

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.

marked as duplicate by Bharat Mane, Niels van Reijmersdal, IAmMilinPatel, NarendraC, ECiurleo Jun 28 '17 at 10:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 '17 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 '17 at 22:12
0

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.