2

I have following code

IWebElement chooseFile = driver.FindElement(By.XPath("//button[@id='btnSelect']"));
chooseFile.SendKeys(@"D:\Workspace\Base Version (Do Not Use)\file.tar.gz");

Its opening up File Explorer but not uploading the file. I tried using JavaScript Executer as below

String filePath = "D:\\Workspace\\Base Version (Do Not Use)\\5GGW3-OMNI-1_R220200BhaT0301E0266.tar.gz";
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("document.getElementById('btnSelect').value='" + filePath + "';");

didn't work either. Does anyone know of any solution? I'm using FirefoxDriver in C# .NET

1 Answer 1

1

You are trying to send a file to a wrong element.
A web element actually receiving uploaded file on a web page is normally matching this XPath: //input[@type='file'].
It is not a visible element.
So, instead of

IWebElement chooseFile = driver.FindElement(By.XPath("//button[@id='btnSelect']"));

Try using

IWebElement chooseFile = driver.FindElement(By.XPath("//input[@type='file']"));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Prophet yes I was sending it to element which is not an input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.