I am trying the code from the following URL and it seems to be working for Opera- Drive Opera with selenium python
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('D:\Driver\operadriver_win64\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()
But I get error when trying to search in Youtube with the following Xpath code-
driver.get('https://youtube.com/')
input_txt = driver.find_element_by_xpath('//*[@id="search"]')
input_txt.send_keys('operadriver\n')
Error
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)
Any suggestion why it's not working for youtube?
CodePudding user response:
Try this
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')