I'm tyring to test the Python Selenium and I have this code:
from selenium import webdriver
url = 'https://www.youtube.com/channel/UC8tgRQ7DOzAbn9L7zDL8mLg/videos'
driver = webdriver.Chrome()
driver.get(url)
videos = driver.find_elements_by_class_name('style-scope ytd-grid-renderer')
for video in videos:
title = video.find_elements_by_xpath('.//*[@id="video-title"]').text
views = video.find_elements_by_xpath('.//*[@id="metadata-line"]/span[1]').text
when = video.find_elements_by_xpath('.//*[@id="metadata-line"]/span[2]').text
print(title,views,when)
And during run I have this error:
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted
(Session info: chrome=85.0.4183.83)
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.18363 x86_64)
If not finding Xpath , try using css selectors. In your case, the following line of code should help you get the element you want :
Or else you can try