问题
Recently Selenium chrome webdriver started to run into problems by triggering Microsoft Malicious Software Removal Tool to request if it may reset browser settings. How to get around this? Is there an argument to add to options like --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)
A temporary solution may be
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')
but nothing happens.
What works (but obviously not ideal) is to execute javascript to close the undesired tab:
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)
来源:https://stackoverflow.com/questions/43368028/how-to-prevent-python-selenium-webdriver-from-triggering-microsoft-malicious