【问题标题】:webdriver + reset Chrome网络驱动程序 + 重置 Chrome
【发布时间】:2017-03-01 11:04:25
【问题描述】:

我正在尝试使用 webdriver(python) 来“重置”Chrome 浏览器。我正在做的是:

driver = webdriver.Chrome()

driver.get('chrome://settings/resetProfileSettings')

上面显示带有“重置”按钮的弹出窗口,我无法使用它找到它

driver.find_element_somehow

请帮我想办法点击“重置”按钮。

注意:我还试图擦除“~/.config/google-chrome/”中的所有文件,但这并不能满足需求。

【问题讨论】:

    标签: python google-chrome webdriver


    【解决方案1】:
    driver = webdriver.Chrome()
    main_window_handle = None
    while not main_window_handle:
        main_window_handle = driver.current_window_handle
    popup_handle = None
    while not popup_handle:
        for handle in driver.window_handles:
            if handle != main_window_handle:
                popup_handle = handle
                break
    driver.switch_to.window(popup_handle)
    driver.find_element_by_xpath(u'XPATH OF RESET BUTTON').click()
    driver.switch_to.window(main_window_handle)
    

    我认为switch_to.window(handle) 最近已被弃用,因此请使用:

    switch_to_window(handle)
    

    【讨论】:

    • 很遗憾,selenium 仍然无法定位元素并引发异常
    【解决方案2】:

    找到解决方案,希望对某人有所帮助。 它在 iframe 中,所以我这样做了:

    driver.switch_to_frame('settings')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      相关资源
      最近更新 更多