Issue
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
Solution
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']"));
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.