简体   繁体   English

无法访问页面上的元素(Selenium Python)

[英]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我正在尝试访问此页面上的元素: https ://www.tiktok.com/search?q=funny%20dog%20videos

I can only access the highest elements (for example, the element with the ID "app").我只能访问最高的元素(例如,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).每当我尝试访问任何其他元素时,都会出现Exception has occurred: NoSuchElementException错误(检查我的代码和网站以查看我所指的内容)。 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.我知道页面上没有 iframe(至少我可以找到)。 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或使用 CSS-selector 搜索

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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