如何防止(python)Selenium webdriver触发“Microsoft恶意软件删除工具”,询问它是否可能重置浏览器设置?

时间:2017-04-12 11:15:47

标签: python windows selenium selenium-webdriver selenium-chromedriver

最近Selenium chrome webdriver通过触发Microsoft恶意软件删除工具开始遇到问题,以请求它是否可以重置浏览器设置。怎么解决这个问题?是否有一个参数可以添加到--disable-extensions solved a popup problem before等选项中?

    from selenium import webdriver
    options = webdriver.chrome.options.Options()
    options.add_argument("--disable-extensions")
    driver = webdriver.Chrome(chrome_options=options)

enter image description here

临时解决方案可能是

driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')

但没有任何反应。

什么有效(但显然不理想)是执行javascript来关闭不需要的标签:

time.sleep(0.2) # give some time for the tabs to appear

# just to understand that the first tab is counter-intuitivly the last of window.handles change the content of each tap
js = "document.getElementsByTagName('body')[0].innerHTML = 'This is handle {0}: {1}';"
for i, handle in enumerate(driver.window_handles):
    driver.switch_to_window(handle)
    driver.execute_script(js.format(i,handle))

# now close the msrt tab and make the desired tab active    
handle_desired, handle_msrt = driver.window_handles # last handle is first tab
driver.switch_to_window(handle_msrt)
driver.execute_script('window.close()') # close the msrt tab
driver.switch_to_window(handle_desired)

0 个答案:

没有答案
相关问题