最近,Selenium chrome webdriver开始遇到问题,触发Microsoft恶意软件删除工具来请求重置浏览器设置。 如何解决这个问题? 是否有一个参数添加到选项--disable-extensions
解决了popup的问题之前 ?
from selenium import webdriver options = webdriver.chrome.options.Options() options.add_argument("--disable-extensions") driver = webdriver.Chrome(chrome_options=options)
临时解决scheme可能是
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')
但没有任何反应。
什么工作(但显然不是理想的)是执行javascriptclosures不需要的选项卡:
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)