gpt4 book ai didi

python - Selenium 无法访问Youtube搜索栏?

转载 作者:行者123 更新时间:2023-12-03 05:28:28 25 4
gpt4 key购买 nike

我试图让Selenium为我做一个Youtube搜索,然后我进入了最后一步,实际上是输入文本,但我陷入了困境。 searchElem使用允许我使用.click()的ID,但是我无法使用具有该ID的send_keys(),因此我尝试了inputElem,但这也不起作用。
没有更具体的ID或类可用于搜索输入,因此我不确定该怎么做。
以下是我尝试将send_keys()与searchElem和inputElem结合使用时遇到的错误。

selenium.common.exceptions.ElementNotInteractableException: Message: Element <div id="search-input" class="ytd-searchbox-spt"> is not reachable by keyboard
这是我针对WebDriver和源代码中的元素的代码。
driver = webdriver.Firefox()
driver.get('https://www.youtube.com')

searchElem = driver.find_element_by_id('search-input')
inputElem = driver.find_element_by_id('search')

searchElem.click()
searchElem.send_keys('election')

最佳答案

'search'可能是要拾取的另一个元素的ID,因此请尝试使用xpath

inputElem = browser.find_element_by_xpath('/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/div/div[1]/input')

inputElem.send_keys('election')

关于python - Selenium 无法访问Youtube搜索栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63607813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com