【问题标题】:Default download directory Edge web driver - python默认下载目录 Edge web driver - python
【发布时间】:2021-07-28 17:51:53
【问题描述】:

我正在尝试更改我的 Microsoft Edge 网络驱动程序的下载位置,但它似乎不起作用。

我已经尝试查看 chrome 的选项并将其复制到 Edge 中,这就是我目前所得到的

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
import time
from datetime import datetime

PATH =r"C:\Users\Username\Desktop\test\msedgedriver.exe"

options = EdgeOptions()
options.add_argument(r"download.default_directory=C:\Users\username\Desktop\test")

driver = Edge(PATH)

有人可以建议吗?

谢谢。

【问题讨论】:

  • 您好,请问您是否有机会查看我的回答?我下面的回答对解决问题有帮助吗?

标签: python selenium selenium-webdriver microsoft-edge


【解决方案1】:

您的代码似乎有一些问题。使用 Selenium 自动化 Edge 时,您可以参考以下步骤更改下载路径:

  1. here 下载正确版本的 Edge WebDriver。确保 Edge WebDriver 版本与 Edge 浏览器版本相同。

  2. 使用以下命令安装 MS Edge Selenium 工具:

    pip install msedge-selenium-tools selenium==3.141
    
  3. 运行以下示例 python 代码进行测试:

    from msedge.selenium_tools import Edge, EdgeOptions
    
    options = EdgeOptions()
    options.use_chromium = True
    options.add_experimental_option("prefs", {
      "download.default_directory": r"D:\Downloads"
    })
    driver = Edge(executable_path=r"D:\webdriver\msedgedriver.exe", options=options)
    driver.get("https://www.seleniumhq.org/download/");
    m = driver.find_element_by_link_text("32 bit Windows IE")
    m.click()
    

    注意:将代码中的路径更改为您自己的。

【讨论】:

    猜你喜欢
    • 2020-01-28
    • 1970-01-01
    • 2013-07-11
    • 2016-05-28
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    相关资源
    最近更新 更多