我正在使用最新的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/