【发布时间】:2022-12-04 12:58:18
【问题描述】:
我刚刚开始探索 Python 和自动化测试 想要创建一个快速脚本,它将:
- 打开 YouTube 页面
- 找到我将插入搜索查询的搜索输入字段
- 在字段中插入搜索查询
- 按下按钮接收搜索结果
不幸的是我遇到了一个错误: “selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互”
请协助
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
link = "https://www.youtube.com/"
browser = webdriver.Chrome()
browser.get(link)
search_string = browser.find_element(By.XPATH, "/html/body/ytd-app/div[1]/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/div[1]/div[1]/div/div[2]/input")
search_string.send_keys("Test search input")
button = browser.find_element(By.XPATH, '/html/body/ytd-app/div[1]/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/button')
button.click()
【问题讨论】: