Not able to upload file with Chrome in Mac OSX

I’m am trying to test a document upload in the browser, and have tried several combinations of things to get this to work. Generally, the idea is:

.then(function () {
	return $browser.waitForAndFindElement(By.css(CSS_SELECTOR), DefaultTimeout); })
.then(function (el) { 
            el.sendKeys(PATH TO LOCAL FILE); })

I have also tried it with el(click); before the sendKeys command, but changed that based on one post online I have read. I have also tried it with one line:

$browser.findElement(By.css(CSS_SELECTOR)).sendKeys(PATH TO LOCAL FILE);

Each time, I am getting the error:

node_modules/selenium-webdriver/lib/goog/async/nexttick.js:39
  goog.global.setTimeout(function() { throw exception; }, 0);
                                        ^
UnknownError: unknown error: cannot focus element
  (Session info: chrome=47.0.2526.111)

Any help would be appreciated!

As the synthetic is running from a cloud server, where would the file be uploaded from?

@edgarn without any additional context, it sounds like from the error message that the file upload widget is either disabled or overlaid by another element. The syntax you have for the .findElement().sendKeys() is correct. The error is pointing to an issue with manipulating that DOM element.

Actually, that is my next question. I was running that test locally and have been able to upload a file using that syntax. But now I am wondering how I might access a file (either via a url or a private folder that can be hosted in the cloud server that’s linked to my acount) when running a test on Synthetics’ node environment?

@edgarn could there be an overlay element in front of your element? It’s very odd that selenium would complain about not being able to focus

There is a File upload example and another example to Upload a binary file.

Hope these are helpful.

2 Likes