简体   繁体   中英

Can't Access Elements On Page (Selenium Python)

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

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM