繁体   English   中英

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

[英]Can't Access Elements On Page (Selenium Python)

我正在尝试访问此页面上的元素: https ://www.tiktok.com/search?q=funny%20dog%20videos

我只能访问最高的元素(例如,ID 为“app”的元素)。 每当我尝试访问任何其他元素时,都会出现Exception has occurred: NoSuchElementException错误(检查我的代码和网站以查看我所指的内容)。 一定有什么东西在路上,但我不知道是什么。

我的代码:

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

我知道页面上没有 iframe(至少我可以找到)。 我也知道只有一个窗把手。 我访问元素的方式可能是什么?

第二行不起作用,因为您不能传递多个类名来按类名搜索。 尝试通过单个类名选择元素,例如

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

或者

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

或使用 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