1

I have a browse file button. When i am trying to attach file, selenium does not interact with file's dialog window.

How can i interact with dialog page or set file path to input?

Community
  • 1
  • 1

2 Answers2

1

I solved this problem. I create input with bootstrap and input was hidden. Before run test i execute this code;

IJavaScriptExecutor js = Browser as IJavaScriptExecutor;
js.ExecuteScript("return $('input').show()");

this javascript code ensure input elements' remove hidden attributes. So run this code and send path to input;

driver.findElement(By.id("myUploadElement")).sendKeys("<PathToMyFile>");
0

Sometimes sendkeys method does not work especially, when we have file upload without using input tag. you can consider using autoit for this.

Autoit will help you to choose a file in file browser.

Your code should be like :-

Click on browse button. call a cmd executable in your code (which will execute your autoit code and will select a file). and then, continue with normal execution.

If require, I can post my auto it script here, but will after 2-3 days as I don't have access to my system during this period.

Anil Chandna
  • 180
  • 1
  • 9