ElementNotVisibleException:消息:尝试在YouTube搜索中单击顶部视频时,元素不可交互错误

ElementNotVisibleException:消息:尝试在YouTube搜索中单击顶部视频时,元素不可交互错误,第1张

ElementNotVisibleException:消息:尝试在YouTube搜索中单击顶部视频时,元素不可交互错误

你快到了 您需要诱导 WebDriverWait 来使 元素可单击, 并且可以使用以下解决方案:

  • 代码块:

    from selenium import webdriver

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    wrds = [“Vivaldi four seasons”, “The Beatles twist and shout”, “50 cent heat”]
    kwrd = [“Vivaldi”, “Beatles”, “50”]
    options = webdriver.ChromeOptions()
    options.add_argument(“start-maximized”)
    options.add_argument(“disable-infobars”)
    options.add_argument(“–disable-extensions”)
    driver=webdriver.Chrome(chrome_options=options, executable_path=r’C:WebDriverschromedriver.exe’)
    for i, j in zip(wrds, kwrd):
    driver.get("https://www.youtube.com/”)
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, “input#search”))).send_keys(i)
    driver.find_element_by_css_selector(“button.style-scope.ytd-searchbox#search-icon-legacy”).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, “h3.title-and-badge.style-scope.ytd-video-renderer a”))).click()
    WebDriverWait(driver, 10).until(EC.title_contains(j))
    print(driver.current_url)
    driver.quit()



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5586098.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存