python-3.x - ElementNotInteractableException:消息:使用Selenium和ChromeDriver单击youtube搜索按钮时,元素不可交互错误

标签 python-3.x selenium-webdriver xpath youtube css-selectors

我正在使用最新的python和最新的Selenium chrome webdriver。我正在尝试使用一个简单的代码在youtube中进行搜索,但出现以下错误。谁能帮我?

File "search.py", line 8, in <module> searchBox.click()
Selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

CodeStarts在这里:
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://youtube.com')

searchBox = driver.find_element_by_xpath('//*[@id="search"]')
if searchBox.is_enabled():
    searchBox.click()
    searchBox.send_keys("youtube test")
    searchButton = driver.find_element_by_xpath('//*[@id="search-icon-legacy"]/yt-icon')
    searchButton.click()
else:
    print("What the heck")
#CodeEndsHere

最佳答案

我在YouTube网站首页上发现了3个带有标签的元素,第一个元素不可见,第二个元素是您要访问的搜索字段。
使用此标签:

"//div[@id='search-input']"

关于python-3.x - ElementNotInteractableException:消息:使用Selenium和ChromeDriver单击youtube搜索按钮时,元素不可交互错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62234950/

相关文章:

python - 如何随机生成非常小的数字?

java - 在同一个 Selenium 网格节点上运行 PhantomJS 和 Chrome 浏览器

html - 抓取页面源代码的可靠方法,即每行开头的电视?

xpath - 模拟 HttpServlet 响应 : Checking xml content

ruby - 如何获取<br> 或<br/> 之间文本的xpath?

python - pyqt QFileSystemModel rowCount

python - 我怎样才能让我的角色停止越过屏幕的右侧?

python - 将子字符串列表添加到 python 中字符串的特定位置

java - 通过 PID 进程杀死 Selenium 浏览器 [Java]

python - selenium.common.exceptions.ElementClickInterceptedException : Message: element click intercepted: 的问题