0

SO normally I don't have a hard time with radio buttons but I was trying to configure the web browsers set home page to custom URL from the chrome settings. I knew I would have to activate the drop down box that lets me (picture provided). I located what I think is the source and had to navigate my way through some shadow DOM's. however after getting to the path I tried to click on it I get the error

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (311, 1418)

I'm confused and I've been fighting this off for a while. Any one have any idea? I did notice some of the settings change when I personally click on the different options. here are the pictures

enter image description here

enter image description here

Heres my code:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
def expand_shadow_element(element):
    shadow_root = cdriver.execute_script('return arguments[0].shadowRoot', element)
    return shadow_root
#chrom driver
cdriver = webdriver.Chrome(executable_path='C:\\Users\\name\Downloads\\chromedriver.exe')
#open up page to chrome settings.
cdriver.get('chrome://settings/')

root1 = cdriver.find_element_by_tag_name('settings-ui')
shadow_root1 = expand_shadow_element(root1)

root2 = shadow_root1.find_element_by_id('main')
shadow_root2 = expand_shadow_element(root2)

root3 = shadow_root2.find_element_by_tag_name('settings-basic-page')
shadow_root3 = expand_shadow_element(root3)

root4 = shadow_root3.find_element_by_tag_name('settings-on-startup-page')
shadow_root4 = expand_shadow_element(root4)

root5 = shadow_root4.find_element_by_name('4')
shadow_root5 = expand_shadow_element(root5)

root6 = shadow_root5.find_element_by_id('button')
root6.click()

anyone have any idea why I cant click on the source? i even right clicked on the radio button and thats the source I was pointed to.

CEH
  • 5,701
  • 2
  • 16
  • 40
Jbravo
  • 43
  • 6

1 Answers1

0

To work around the element click intercepted error, you can try a Javascript click and see if that works for you.

The DOM tree is a bit hard to follow, but I think I catch the drift here -- a radio setting is under controlled-radio-button element, and the little circle itself is <div class='disc'>, as highlighted in your code sample.

I didn't see a shadow root under <div id="button"> that you store in root6 -- I see the element, but not a shadow root, so I am assuming the radio button itself actually lives under root5.

With that being said, here's some code to click on a radio button (given its description) using Javascript:

# grab the radio element... tricky with shadow roots
radio_button = root5.find_element_by_xpath("//div[@id='button']/div[@class='disc']")

# attempt to click it using JS -- ignores ClickIntercepted error
driver.execute_script("arguments[0].click();", radio_button)

Because you have already located the correct radio group and stored the shadow elements in root5 variable, you can try to use find_element_by_xpath on root5 to grab the <div class="disc"> element that appears right under it. The Javascript click should hopefully work around the ClickIntercepted error.

CEH
  • 5,701
  • 2
  • 16
  • 40
  • Thank you so much! It worked and it took me a while to read and understand what the solution was. I'm still really new at this. – Jbravo Nov 18 '19 at 18:34
  • Working with shadow roots is quite tricky and takes lots of practice to get used to. The answer on this question helped me break down the concept to understand everything a little better: https://stackoverflow.com/questions/36656667/need-help-understanding-the-shadow-dom/36657815 – CEH Nov 18 '19 at 19:27
  • Again, Thank you so much! – Jbravo Nov 18 '19 at 20:07