When writing the file upload script, encountered a lot of problems, including element positioning, as well as upload operations, now summarizes the following points:
1. Upload the control positioning to be accurate, when necessary to wait
Webelement adfileupload = driver.findelement (By.xpath ("//input[@type = ' file ']");
2. Upload operation
String FilePath = "d:\\taxonomy\\db\\haiertaxonomy.xlsx"; Adfileupload.sendkeys (FilePath); try {thread.sleep (10000); } catch (Interruptedexception e) {e.printstacktrace (); } driver.findelement (By.xpath ("//button[@class = ' btn btn-primary start '] [@type = ' button ']"). Click (); Driver.manage (). Timeouts (). implicitlywait (Timeunit.seconds); Driver.findelement (By.xpath ("//input[@id = ' Complete-template-upload ' [@type = ' button ']"). Click ();
3. As the script above, the path of the file must be accurate, or even if the script is not error, the file still upload failed.
Selenium File Upload java Script