Featured image of post Python selenium 解決 chrome://settings 無法定位問題

Python selenium 解決 chrome://settings 無法定位問題

大神解答:

stackoverflow-56763683

stackoverflow-56380091

實作範例

  1. 清除瀏覽紀錄按鈕
1
return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-section > settings-privacy-page').shadowRoot.querySelector('settings-clear-browsing-data-dialog').shadowRoot.querySelector('#clearBrowsingDataDialog').querySelector('#clearBrowsingDataConfirm')
  1. 新增聲音按鈕
1
return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-privacy-page').shadowRoot.querySelector('settings-animated-pages > settings-subpage > category-setting-exceptions').shadowRoot.querySelector('site-list').shadowRoot.querySelector('#addSite')
  1. 新增聲音按鈕
1
return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-privacy-page').shadowRoot.querySelector('settings-animated-pages > settings-subpage > category-setting-exceptions').shadowRoot.querySelector('site-list').shadowRoot.querySelector('add-site-dialog').shadowRoot.querySelector('#site').shadowRoot.querySelector('#input')
  1. 新增聲音確認新增按鈕
1
return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-privacy-page').shadowRoot.querySelector('settings-animated-pages > settings-subpage > category-setting-exceptions').shadowRoot.querySelector('site-list').shadowRoot.querySelector('add-site-dialog').shadowRoot.querySelector('#add')

Python:

1
2
3
clearButton = browser.execute_script("return document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-privacy-page').shadowRoot.querySelector('settings-animated-pages > settings-subpage > category-setting-exceptions').shadowRoot.querySelector('site-list').shadowRoot.querySelector('#addSite')")
#click on the clear button now
clearButton.click()
使用 Hugo 建立
主題 StackJimmy 設計