我有一个基本的设置方法:
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()
当我在另一个测试中调用此设置方法时。我的文件一直在默认下载文件夹中下载,而我想在单击 C:\Users\cverma\Desktop\SOAPProject
最佳答案
尝试以下操作:
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 将仅使用“下载”文件夹作为默认文件夹
关于python - 文件在默认下载文件夹中持续下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41047351/