0

I'm trying to give simple input in the Youtube search box. I get this error:

selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable

This is my code:

from selenium import webdriver
browser = webdriver.Opera()
browser.set_window_position(0,0)
browser.set_window_size(1366, 768)
browser.get('https://youtube.com')
elem = browser.find_element_by_xpath('//*[@id="search"]')
elem.click()
elem.sendkeys('cats')

Could it be because the page doesn't load fast enough?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
gleb
  • 1
  • 1

3 Answers3

0

Yes you are right, the page doesn't load fast enough. You can fix it with this line, so that selenium waits for page to load after it gets to it.

time.sleep(5)

If it doesn't load in 5 sec you can make it a bigger wait.

joc
  • 179
  • 5
0

Look at below the post, which will help you to wait until the page loads Wait until page is loaded with Selenium WebDriver for Python

This is another alternative, instead of using time.sleep()

  • did that and now this is the error that I get : elem.sendkeys('cats') AttributeError: 'WebElement' object has no attribute 'sendkeys' – gleb May 10 '20 at 12:53
0

The simplest and least wasteful of time as far as waiting longer than necessary would be:

browser = webdriver.Opera()
browser.implicitly_wait(10) # or even longer than 10 seconds

Then after you do a elem.click() followed by an browser.find_by_xpath() for some element on the new page (or use one of the other methods for locating an element), the driver will wait for up to 10 seconds for the element you are looking for to appear following the click before it times out (but, of course, if the new page comes down more quickly you will wait only as long as you have to).

Your elem.sendkeys should be elem.send_keys and surely elem should some element on the new page that you have first located.

Booboo
  • 38,656
  • 3
  • 37
  • 60