A
A
Arbil2020-07-03 14:39:18
Python
Arbil, 2020-07-03 14:39:18

Why is the get method not working in the code?

In fact, this code should open a page on YouTube.

from selenium import webdriver

def main():
    driver = webdriver.Chrome()
    driver.get("https://www.youtube.com/")

main()

But instead it only opens the start page

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2020-07-03
kuzmin @sergueik

add page wait

url = 'https://www.youtube.com/'
  title = 'YouTube'
  
  driver = webdriver.Chrome()
  driver.get(url)
  try:
    # https://selenium-python.readthedocs.io/waits.html
    WebDriverWait(driver,10).until(EC.title_contains(title))

  except (NoAlertPresentException, TimeoutException) as e:
    print('page was not shown: {0}'.format(e))
  finally:
    driver.quit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question