Probleme beim automatischen Download von Dateien in Python Selen

1339
Samadhan Gaikwad

Ich habe folgenden Code, der gut funktioniert, um durch 3 Seiten zu navigieren und auf den Link zum Herunterladen der CSV-Datei in Firefox zu klicken. Bei der Profileinstellung kann der Download jedoch nicht automatisch heruntergeladen werden. Hilfe bitte. Ich habe am Start die Profileinstellung eingestellt, ist es richtig ...?

from lib2to3.pgen2 import driver from selenium import webdriver import unittest from webbrowser import browser from selenium.webdriver.common.keys import Keys import selenium import time  class UnitTestExample(unittest.TestCase):  def setUp(self): profile = webdriver.FirefoxProfile() profile.set_preference("browser.download.folderList", 2) profile.set_preference("browser.download.manager.showWhenStarting", False) profile.set_preference("browser.download.dir", "C:\Python34") profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")  self.driver = webdriver.Firefox(firefox_profile=profile) # note that this creates a class instance variable self.driver.implicitly_wait(30) # when testing AJAX this would not be used self.base_url = "https://webtac.industrysoftware.automation.siemens.com/webpr/webpr.php?objtype=frames&g_userid=fddd&g_session_id=7311876" # sets up another class instance variable self.verificationErrors = []  def testWebSite1(self): # a first test case there can be others driver = self.driver # class instance variable used here driver.get( "https://webtac.industrysoftware.automation.siemens.com/webpr/webpr.php?objtype=frames&g_userid=a3rgcw&g_session_id=7311876")  username = driver.find_element_by_id("username") password = driver.find_element_by_id("password")  username.send_keys("username") password.send_keys("password")  ### driver.find_element_by_class_name("btn btn-primary").send_keys("\n")  driver.find_element_by_xpath('//button[@type="submit"]').submit() time.sleep(30) # Call java fuction and web page loads driver.execute_script('javascript:parent.gotoSearch(\'advanced\')') # Add below dates in input fields time.sleep(10)  driver.switch_to.frame(0) time.sleep(10)  openf = driver.find_element_by_id("openedFrom_dateText") opent = driver.find_element_by_id("openedTo_dateText") openf.clear(); openf.send_keys("01-Jan-2015") opent.clear(); opent.send_keys("02-Jan-2015") time.sleep(20) # Print status print(driver.current_url) window_before = driver.window_handles[0] print(window_before)  #Button click driver.find_element_by_xpath('//input[@type="button"]').click() time.sleep(10)  window_after = driver.window_handles[1] driver.switch_to.window(window_after) print(driver.current_url) driver.find_element_by_link_text("[Comma-Delimited Text (CSV)]").click() print(window_after) time.sleep(10) def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors)   if __name__ == "__main__": # allows unittest to start by running this class file unittest.main() # start the main method of unittest 
1

0 Antworten auf die Frage