Guest User

Untitled

a guest
Jun 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. String script = "document.getElementById('fileName').value='" + "C:\\temp\\file.txt" + "';";
  2. ((IJavaScriptExecutor)driver).ExecuteScript(script);
  3.  
  4. driver.find_element(:id, 'upload').send_keys('/foo/bar')
  5.  
  6. # presumes webdriver has loaded the web page of interest
  7. element_input = webdriver.find_element_by_css_selector('input[id="uploadfile"]')
  8. handle_dialog(element_input, "foobar.txt")
  9.  
  10. def handle_dialog(element_initiating_dialog, dialog_text_input):
  11. def _handle_dialog(_element_initiating_dialog):
  12. _element_initiating_dialog.click() # thread hangs here until upload dialog closes
  13. t = threading.Thread(target=_handle_dialog, args=[element_initiating_dialog] )
  14. t.start()
  15. time.sleep(1) # poor thread synchronization, but good enough
  16.  
  17. upload_dialog = webdriver.switch_to_active_element()
  18. upload_dialog.send_keys(dialog_text_input)
  19. upload_dialog.send_keys(selenium.webdriver.common.keys.Keys.ENTER) # the ENTER key closes the upload dialog, other thread exits
  20.  
  21. string filePath = @"drive:pathfilename.filextension";
  22. driver.FindElement(By.Id("fileInput")).SendKeys(filePath);
  23.  
  24. string filePath = "drive:/path/filename.filextension";
  25. driver.FindElement(By.Id("fileInput")).SendKeys(filePath);
  26.  
  27. @driver.find_element(:xpath, "html/body/div[1]/div[2]/div[1]/form/div[4]/div[7]/table/tbody/tr[1]/td[2]/input").send_keys "C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg"
Add Comment
Please, Sign In to add comment