I'm making a search on Youtube, then I press a few TAB, then I press a few END via the ActionChains... Then I want to grab the results and if I find what I want, I want to click on it.
driver.get('https://www.youtube.com')
time.sleep(4)
items = driver.find_element(By.XPATH, "//input[@id='search']")
rand = random.choice(query)
items.send_keys(rand)
items.send_keys(Keys.RETURN)
time.sleep(2)
action = ActionChains(driver)
for i in range(5):
action.send_keys(Keys.TAB)
action.perform()
time.sleep(1)
for i in range(3):
action.send_keys(Keys.END)
action.perform()
time.sleep(4)
items = driver.find_elements(By.XPATH, "//div[@id='primary']//a[@id='thumbnail'][@class='yt-simple-endpoint inline-block style-scope ytd-thumbnail'][contains(@href, 'watch?v=')]")
for i in items:
if ......... :
i.click()
Usually, after using: driver.find_elements(By.XPATH....
I can do a
for i in items:
if ...... :
i.click()
But now it's not working since I've been using the action = ActionChains(driver)
I'm getting this error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
CodePudding user response:
I found my answer, the problem is youtube and not selenium. i.click() works, the problem was my find_elements(By.XPATH, ... youtube also has invisible elements form the home page that are included in the result page, which gave me invisible items.
once I changed my XPATH to:
//ytd-search[@class='style-scope ytd-page-manager']//div[@id='primary']//a[@id='thumbnail'][@class='yt-simple-endpoint inline-block style-scope ytd-thumbnail'][contains(@href, 'watch?v=')]")
it worked