[英]Download the file with Selenium python in a desired folder or current tests directory folder
我正在嘗試使用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()
現在,當我使用此設置方法運行測試時,測試會將文件保存在下載目錄中。
請嘗試以下操作:
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"
值,您將不會獲得任何例外chromedriver
將僅使用Downloads
文件夾作為默認文件夾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.