-1

I'm trying to get Python Selenium to press the button by finding the certain element from the XPATH. I have been able to do this for other instances, but this particular one is being weird and I don't understand why.

So to help visualize what's going on, I'm using the Google Chrome extension "XPath Helper". But even when I copy the XPath directly from the inspect element page and paste it, it comes out as null. Below is a screenshot as well as a link to the subreddit post I'm using. I just want to find all the elements with that minus symbol, the "comment-fold-button"

The page is being accessed with no account. I am not logged in intentionally.

link to subreddit post

Screenshot of my page

So to help visualize what's going on, I'm using the Google Chrome extension "XPath Helper". But even when I copy the XPath directly from the inspect element page and paste it, it comes out as null. Above is a screenshot as well as a link to the subreddit post I'm using. I just want to find all the elements with that minus symbol, the "comment-fold-button"

Fluff
  • 19
  • 3

1 Answers1

0

The desired <button> elements are within #shadow-root (open):

multipleShadowRoot

So Selenium can find those elements readily.


Solution

You need to use shadowRoot.querySelector() command to locate the elements as follows:

document.querySelector('shreddit-comment').shadowRoot.querySelector('#comment-fold-button')

Console snapshot:

comment-fold-button

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352