How to search and open a Youtube video with selenium?
import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() driver.maximize_window() wait = WebDriverWait(driver, 3) presence = EC.presence_of_element_located visible = EC.visibility_of_element_located # Navigate to url with video being appended to search_query video = 'dragon city best hack tool' driver.get("https://www.youtube.com/results?search_query=" + str(video)) # play the video driver.find_elements_by_xpath('/html/body/ytd-app/div/ytd-page-manager/ytd-search/div[1]/ytd-two-column-search-results-renderer/div/ytd-section-list-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-shelf-renderer/div[1]/div[2]/ytd-vertical-list-renderer/div[1]/ytd-video-renderer[2]/div[1]/div/div[1]/div/h3/a').click() time.sleep(20)