【发布时间】:2020-08-04 07:48:24
【问题描述】:
错误信息:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: input.ytd-searchbox
我不断收到此错误,即使我从其他解决方案中添加了一个睡眠命令以使页面使用 javascript 动态加载,但它仍然找不到它?
import time
from selenium import webdriver
firefox = webdriver.Firefox()
firefox.get("https://www.youtube.com")
element = firefox.find_element_by_css_selector("ytd-mini-guide-entry-renderer.style-scope:nth-child(3) > a:nth-child(1)") # opens subscriptions
element.click()
time.sleep(10) # wait for page to load before finding it
searchelement = firefox.find_element_by_css_selector('input.ytd-searchbox') # search bar
searchelement.send_keys("Cute Puppies")
searchelement.submit()
【问题讨论】:
-
检查 selenium 开箱即用的等待功能 selenium-python.readthedocs.io/waits.html
标签: python selenium web-scraping time youtube