I've got a page with both text, text fields, normal form buttons and a file upload button (which opens a file upload dialog).
All the other elements can be accessed, except the file upload button. I've tried with both .Click() and JavaScriptExecutor, but as far as I can see (visually) the file dialog never opens. There are no error messages, though.
The page source:
<a class="bttngrey file-input-container bttn-small" data-bind="enable: !uploading() " style="margin-top: 10px; ... data-original-title="Add attachment"> <i class="fa fa-cloud-upload">...</i> <input type="file" data-bind="upload: addAttachments, enable: !uploading()"> == $9
C#/Selenium code to click the button:
NB: I'm using a Button class and a JavaScriptActions class to handle the call to the ChromeDriver instance, instead of calling it directly. I hope the code snippets make sense.
Button.FindByXPath("/html/body/div[1]/div[2]/overlay--master/div/div/overlay-lightbox/div/div[3]/content-placeholder/a").Click(); JavaScriptActions.ButtonClickXPath("/html/body/div[1]/div[2]/overlay--master/div/div/overlay-lightbox/div/div[3]/content-placeholder/a"); public class Button { public static IWebElement FindByXPath (string bttnxpath) { return GCDriver.Instance.FindElement(By.XPath(bttnxpath)); } } public class JavascriptActions { public static void ButtonClickXPath (string xpath) { GCDriver.JSClickXPath(xpath); } } public class GCDriver { .... .... .... public static void JSClickXPath (string xpath) { IWebElement icon = Instance.FindElement(By.XPath(xpath)); Actions ob = new Actions(Instance); ob.Click(icon); IAction action = ob.Build(); action.Perform(); } .... .... .... }
None of the methods for clicking the button seems to work. Even though they work for other "normal" buttons on the page. The reason I'm trying JavaScriptExecutor is that I've experience a case earlier where a button like this (that opens a file dialog) wasn't clickable by the normal Selenium method, but it was with JavaScriptExecutor.
The strange thing here is that both methods just finishes without any errors. However, when I'm watching the page, I see no clicking and opening of the dialog. The test just finishes immediately. Adding an explicit wait before and after clicking the button doesn't help either.
Any ideas? I'll elaborate more if necessary; It's not always clear how much code needs to be shown for the question/problem to be clear.