【问题标题】:how to delete youtube's watch later video in selenium?如何删除 youtube 在 selenium 中观看稍后的视频?
【发布时间】:2017-02-27 12:54:16
【问题描述】:

我想删除 youtube 的稍后观看视频。但我的代码不起作用。

<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-default yt-uix-button-empty yt-uix-button-has-icon no-icon-markup pl-video-edit-remove yt-uix-tooltip" type="button" onclick=";return false;" title="Remove"></button>

我的代码是这样的。

_sDriver.get('https://www.youtube.com/playlist?list=WL')
_sDriver.find_element_by_class_name('pl-video-edit-remove').click()

例外是这样。

>>> _sDriver.find_element_by_class_name('pl-video-edit-remove')
    <selenium.webdriver.remote.webelement.WebElement (session="283d423c-5ff7-478f-89
    b9-002499413126", element="{e00dbb1e-e0ca-4f79-8652-23c955b464e7}")>
>>> _sDriver.find_element_by_class_name('pl-video-edit-remove').click()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
    line 72, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 461, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not c
urrently visible and so may not be interacted with
Stacktrace:
    at fxdriver.preconditions.visible (file:///c:/users/admini~1/appdata/local/t
emp/tmppqz9zq/extensions/fxdriver@googlecode.com/components/command-processor.js
:10092)
    at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/admini~1/a
ppdata/local/temp/tmppqz9zq/extensions/fxdriver@googlecode.com/components/comman
d-processor.js:12644)
    at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/admini~1/ap
pdata/local/temp/tmppqz9zq/extensions/fxdriver@googlecode.com/components/command
-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///c:/users/admini~1/appd
ata/local/temp/tmppqz9zq/extensions/fxdriver@googlecode.com/components/command-p
rocessor.js:12666)
    at DelayedCommand.prototype.execute/< (file:///c:/users/admini~1/appdata/loc
al/temp/tmppqz9zq/extensions/fxdriver@googlecode.com/components/command-processo
r.js:12608)

我不知道我能为此做些什么。 我需要你的帮助。 谢谢。

【问题讨论】:

  • 你有什么例外吗?
  • 它对我有用。如果您有任何异常,请分享。
  • 我添加了异常
  • 尝试添加一些显式等待页面完全呈现

标签: python selenium youtube


【解决方案1】:

您尝试单击的元素通常不可见。仅当您将鼠标悬停在其上时才可见。因此,要么在单击之前触发 mouseover 事件,然后尝试它是否有效。

另一种解决方案是您可以尝试执行 JavaScript。

    driver.execute_script("document.getElementsByClassName('pl-video-edit-remove')[0].click()")

脚本在我的最后工作。

您可能希望在执行脚本之前添加一些等待,以便页面正确加载。

【讨论】:

  • 答案因新的 yt 布局而过期
猜你喜欢
  • 2016-03-17
  • 2020-11-02
  • 2019-03-30
  • 2012-05-17
  • 2015-03-13
  • 1970-01-01
  • 2011-09-03
  • 2013-10-29
  • 2019-09-08
相关资源
最近更新 更多