python - 用于 Youtube 的 Python Selenium Opera - 出现错误
问题描述
我正在尝试来自以下 URL 的代码,它似乎适用于 带有 selenium python 的 Opera-Drive Opera
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('.\operadriver.exe')
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')
time.sleep(5) #see the result
driver.quit()
但是尝试使用以下 Xpath 代码在 Youtube 中搜索时出现错误-
driver.get('https://youtube.com/')
input_txt = driver.find_element_by_xpath('//*[@id="search"]')
input_txt.send_keys('operadriver\n')
错误
Traceback (most recent call last):
File "C:\Users\admin\Desktop\py\-test\web\selnm\ytb1.py", line 39, in <module>
input_txt.send_keys('operadriver\n')
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\admin\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=93.0.4577.82)
(Driver info: operadriver=93.0.4577.63 (ff5c0da2ec0adeaed5550e6c7e98417dac77d98a-refs/branch-heads/4577@{#1135}),platform=Windows NT 6.1.7601 SP1 x86_64)
有什么建议为什么它不适用于 youtube?
解决方案
尝试这个
driver.get('https://youtube.com/')
input_txt = driver.find_element_by_xpath('//input[@id="search"]')
input_txt.click()
time.sleep(1)
input_txt.send_keys('operadriver\n')
推荐阅读
- amazon-web-services - 如何在 AWS EC2 上部署 Flutter 网站?
- javascript - useRef 当前仅在第二次更新时获取其值
- c# - WPF:按下 SHIFT 时更改按钮文本
- python-3.x - 同时异步我的代码无法正常工作
- javascript - 如何使用 vue-test-utils 在 vue 中模拟和测试 this.$parents
- jquery - 无法从 li jquery 获取完整日期值
- rxjs - RxJS:速率限制和并发限制在不同地方发出的 HTTP 请求
- ionic-framework - ion-router 中的查询字符串支持(使用 StencilJs)
- angular - ngOnInit vs constructor in Angular
- javascript - 如何设置 event.target.value 的类型?