How to upload a file in Selenium with no text box?
I want to upload a file from my desktop to a specific URL.
The URL has a "file" text box, so when I go to my URL with Firefox and use the File Upload button, it asks me for the file and then opens that file. However, this doesn't work in Selenium. The file is never uploaded. How do I upload a file with no text boxes?
Here's my code: self.webDriver = webdriver.Firefox()
WebDriver.implicitlywait(20) #Go to page. Url = '. WebDriver.get(url) webDriver.findelementbyid('input-file').sendkeys("C:/filepath/file")
#Wait. WebDriver.findelementbyid("input-file").sendkeys("C:/filepath/file")
#Click the submit button. WebDriver.findelementbyid("button-submit").click()
This doesn't work. The webdriver doesn't find the "file" textbox or the submit button. When I look at the page source, it looks like this:
Also, I've tried using Selenium's "clickbutton" command to click the submit button, but the webdriver says that the "button-submit" id is not found, which I think means that the submit button is not even on the page. The submit button is an input element of type button. You should use a different locator to locate it.
Element = webdriver.
How to upload file in Selenium webdriver without using autoit?
In my automation, I had to upload a file in website and perform some tasks and after completed my task have to upload the file again.
So I tried using autoit but its working fine for the uploaded file not for multiple file but when I try to upload multiple file then its throwing error.
Please see my code which are commented where error is shown, this code is throwing error 'File Upload' exception in line: FileName="C:Project WorkAutomationProjectAutoTeststestFileUpload.bat" WebBrowser1.Document.GetElementById("UserId").SetAttribute ("value","testuser");
//WebBrowser1.GetElementById("Password").SetAttribute("value","testuser123");
WebBrowser1.GetElementById("Submit").Click;
WebBrowser1.GetElementById("fFile").SendKeys (FileName); //Line No:33
In above line, the file upload is causing error File Upload exception. Below is the sample error shown System.TypeInitializationException : The type initializer for 'Selenium.IWebDriver' threw an exception. --> System.NullReferenceException : Object reference not set to an instance of an object.bat"
WebBrowser1.GetElementById("UserId").GetElementById("Password").SetAttribute("value","testuser123");
WebBrowser1.GetElementById("Submit").GetElementById("fFile").SendKeys (FileName);
at AutomationProject.GUIClass1.TestRun(GUIForm ufg) in C:Project WorkAutomationProjectAutomationProjectGUIClass1.cs:line 43
at TestMethod1() in C:UserstestuserDesktopAutomationProjectFubyte.WebPage.TestsSelenium.Wpf.Client.
Related Answers
How can we use the Selenium tool with HeadSpin?
Selenium is a tool that is used to automate functional testing. There are two types...
What are 5 Uses of Selenium?
Selenium is a web-automation tool that helps you to test web applications....
How can we use the Selenium tool with HeadSpin?
Selenium is a cross-browser testing automation framework w...