Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

Element cant be found in any way with selenium

$
0
0

I'm attempting to toggle comments using Selenium, but it seems unable to locate the toggle button. I've attempted to locate every SVG element to confirm the presence of the '-' button, but it only seems to find the '+' buttons. Additionally, I've tried to capture screenshots of every button or print out the aria-controls selector to find 'comment-children', but to no avail. Does anyone have any ideas on how to locate the toggle comment button (-)?

random example where i used it:https://www.reddit.com/r/AskReddit/comments/1boxkxx/whats_the_most_surreal_experience_youve_had_that/?sort=top&rdt=57328

I've tried to capture screenshots of every button or print out the aria-controls selector to find 'comment-children', but to no avail.and many other stuff

Here some code for css_selector and xpath

from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.chrome.options import Optionsfrom webdriver_manager.chrome import ChromeDriverManagerfrom selenium.webdriver.chrome.service import Servicefrom selenium.common.exceptions import NoSuchElementExceptionservice = Service(ChromeDriverManager().install())chrome_options = Options()chrome_options.add_experimental_option("detach", True)driver = webdriver.Chrome(service=service, options=chrome_options)driver.get("https://www.reddit.com/r/AskReddit/comments/1boxkxx/whats_the_most_surreal_experience_youve_had_that/?sort=top")driver.set_window_size(1920, 1080)try:    xpath_button = driver.find_element(By.XPATH, "//*[@id='comment-tree']/shreddit-comment[1]//details/div/div[3]/div[1]/button")    print("xpath found")except NoSuchElementException:    print("NoSuchElementException")try:    css_selector_button = driver.find_element(By.CSS_SELECTOR, "[icon-name='leave-outline']")    print("css selector found")except NoSuchElementException:    print("NoSuchElementException")

Output :

NoSuchElementException

NoSuchElementException

Expected Behaviour:xpath found or css selector found


Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>