driver为chrome驱动
清除缓存时需要逐层切入shadowRoot中获取相应的标签
def clear_stash(driver): driver.get("chrome://settings/clearBrowserData/") time.sleep(2) out_window = expand_shadow_element(driver.find_element_by_tag_name("settings-ui"), driver) out_window = expand_shadow_element(out_window.find_element_by_id("main"), driver) out_window = expand_shadow_element(out_window.find_element_by_tag_name("settings-basic-page"), driver) out_window = expand_shadow_element(out_window.find_element_by_tag_name("settings-privacy-page"), driver) out_window_final = expand_shadow_element(out_window.find_element_by_tag_name("settings-clear-browsing-data-dialog"), driver) out_window = expand_shadow_element(out_window_final.find_element_by_id("clearFromBasic"), driver) out_window_button = out_window_final.find_element_by_id("clearBrowsingData/confirm/i") # out_window.find option = out_window.find_element_by_id('dropdownMenu') option.click() time.sleep(1) option.find_elements_by_tag_name("option")[4].click() # option.click() time.sleep(0.5) out_window_button.click() time.sleep(1) def expand_shadow_element(element, driver): shadow_root = driver.execute_script('return arguments[0].shadowRoot', element) # print(shadow_root.get_attribute("innerHTML")) return shadow_root