Python Youtube 版 Selenium Opera - 出现错误
Python Selenium Opera for Youtube - getting error
我正在尝试以下 URL 中的代码,它似乎适用于 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')
我正在尝试以下 URL 中的代码,它似乎适用于 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')