简体   繁体   中英

Python: Manually config Chrome://settings by Selenium remotedriver

I am trying to control chrome://settings via selenium webdriver, the way I'm trying to do it is the following:

driver.get('chrome://settings/content/siteDetails?site=https%3A%2F%2Fwww.google.com')
a_button = WebDriverWait(driver, 5).until(
            EC.presence_of_element_located((By.XPATH, '//select[contains(@id, "permission")]')))

For some reason selenium does not identify the xpath, and in consequence I cannot select it and move inside the settings or change anything

*** selenium.common.exceptions.TimeoutException: Message:

ch//设置

My selenium version is selenium==3.141.0

driver = webdriver.Chrome()

driver.get(
    'chrome://settings/content/siteDetails?site=https%3A%2F%2Fwww.google.com')
temp= driver.execute_script(
    "return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main#main').shadowRoot.querySelector('settings-basic-page')")
rules = driver.execute_script(
    "return arguments[0].shadowRoot.querySelector('settings-privacy-page').shadowRoot.querySelector('settings-animated-pages#pages settings-subpage site-details').shadowRoot.querySelector('div.list-frame:not(div>div.list-frame)')", temp)
location = driver.execute_script(
    "return arguments[0].querySelector('site-details-permission[label=\"Location\"]').shadowRoot.querySelector('#permission')", rules)
camera = driver.execute_script(
    "return arguments[0].querySelector('site-details-permission[label=\"Camera\"]').shadowRoot.querySelector('#permission')", rules)

location.click()
location.find_element_by_id("allow").click()

camera.click()
camera.find_element_by_id("block").click()

Its inside shadowRoot so you have to use execute script and go through each shadow root. In above code you just have to change the label in the 'location' line to change other rules as 'rules' object is parent for all other rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM