2016-12-09 3 views
1

Я пытаюсь загрузить файл с использованием selenium python. У меня есть основной метод установки, который:Загрузите файл с Selenium python в нужную папку или папку с текущими тестами

class BaseTestCase(object): 


    def setUp(self): 
     options = webdriver.ChromeOptions() 
     options.add_argument("download.default_directory=C:\Users\cverma\Desktop\SOAPProject") 

     self.driver = webdriver.Chrome(executable_path=r"C:\chromedriver\chromedriver.exe", chrome_options=options) 
     self.driver.maximize_window() 
     self.driver.get("https://qa.smartsimpleqa.com") 



    def tearDown(self): 
     self.driver.quit() 

Теперь, когда я запускаю свои тесты, используя этот метод настройки моего тест сохраняет файл в каталоге загрузки вместо этого.

ответ

2

Попробуйте следующее:

chromeOptions = webdriver.ChromeOptions() 
prefs = {"download.default_directory" : "C:\Users\cverma\Desktop\SOAPProject\"} 
chromeOptions.add_experimental_option("prefs", prefs) 
driver = webdriver.Chrome(executable_path=r"C:\chromedriver\chromedriver.exe", chrome_options=chromeOptions) 

Также следует знать, что если вы установили неправильный путь, "download.default_directory" значения, вы получите не exceptions- chromedriver не будет использовать только Downloads папку по умолчанию

Смежные вопросы