【问题标题】:Being not able to expand the screen on youtube with python and selenium无法使用 python 和 selenium 在 youtube 上扩展屏幕
【发布时间】:2021-06-02 18:25:42
【问题描述】:

代码:

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



driver=webdriver.Chrome(r"C:\Users\Desktop\chromedriver.exe")
driver.maximize_window()
                    
driver.get("https://www.youtube.com/watch?v=3yjO6yfHLcU&ab_channel=TRT%C4%B0zleTRT%C4%B0zleDo%C4%9Fruland%C4%B1") #the website
 


element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".ytpsize-button ytp-button"))) 
# for maximize window
element.click()

你好朋友,我想扩大视频屏幕,但我做不到。我想知道我该怎么做?有没有其他解决方案可以做到这一点? 当我运行代码时,它有时会等待广告然后什么也没有发生 有时会出现超时错误。

raise TimeoutException(message, screen, stacktrace)

TimeoutException

【问题讨论】:

  • 最大化按钮在哪里?
  • ".ytpsize-button ytp-button"

标签: python-3.x selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

您需要先将鼠标悬停在菜单栏上,然后点击最大化窗口按钮:

示例代码:

wait = WebDriverWait(driver, 10)
driver.get("https://www.youtube.com/watch?v=3yjO6yfHLcU")
ActionChains(driver).move_to_element(wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ytp-chrome-controls")))).perform()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.ytp-fullscreen-button.ytp-button"))).click()

进口:

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

【讨论】:

  • 首先使用 selenium 全屏启动浏览器,然后使用此代码。
猜你喜欢
  • 2022-10-06
  • 1970-01-01
  • 1970-01-01
  • 2022-10-03
  • 1970-01-01
  • 2013-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多