Home > other >  Can't Access Elements On Page (Selenium Python)
Can't Access Elements On Page (Selenium Python)

Time:06-30

I'm trying to access the elements on this page: https://www.tiktok.com/search?q=funny dog videos

I can only access the highest elements (for example, the element with the ID "app"). Whenever I try and access any other element, I get a Exception has occurred: NoSuchElementException error (check my code and the website to see what I'm referring to). Something has to be in the way, but I don't know what is.

MY CODE:

options  = Options()
options.add_argument("--disable-notifications")
options.add_experimental_option("prefs", {"download.default_directory" : r"C:\Users\jack_l\Downloads\TESTING TIKTOK"})

driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
driver.maximize_window()
driver.get('https://www.tiktok.com/search?q=funny dog videos')

action = ActionChains(driver)

driver.find_element(By.ID, 'app') # THIS WORKS
driver.find_element(By.CLASS_NAME, 'tiktok-12azhi0-DivHeaderContainer e10win0d0') #THIS GETS AN ERROR

I know that there is no iframe (that I can find at least) on the page. I also know that there is only one window handle. What could be in my way of accessing the elements?

CodePudding user response:

Second line doesn't work because you cannot pass multiple class names to search by class name. Either try to select element by single class name like

driver.find_element(By.CLASS_NAME, 'tiktok-12azhi0-DivHeaderContainer')

or

driver.find_element(By.CLASS_NAME, 'e10win0d0')

or use search by CSS-selector

driver.find_element(By.CSS_SELECTOR, '.tiktok-12azhi0-DivHeaderContainer.e10win0d0')
  • Related