不能使用镀铬铸造按钮与硒

时间:2017-07-23 20:23:18

标签: python selenium google-cast

我正在尝试使用Selenium将YouTube视频投射到我的chromecast。当我用铬打开youtube时,我看到了转换按钮,它工作正常。当我用Selenium打开它时,丢失了投射按钮,当我从菜单中选择投射时,它给出了错误“找不到投射目的地。需要帮助吗?”

我正在使用python,并尝试过很多标志与webdriver的组合。这就是我所拥有的

options = webdriver.ChromeOptions()

options.add_argument('--user-data-dir=./ChromeProfile')
options.add_argument('--disable-session-crashed-bubble')
options.add_argument('--disable-save-password-bubble')
options.add_argument('--disable-permissions-bubbles')
options.add_argument('--bwsi')
options.add_argument('--load-media-router-component-extension')
options.add_argument('--enable-video-player-chromecast-support');

excludeList = ['disable-component-update',
  'ignore-certificate-errors',
]
options.add_experimental_option('excludeSwitches', excludeList)

chromedriverPath = '/my/path/to/chromedriver'
driver = webdriver.Chrome(chromedriverPath, chrome_options=options)

path = 'https://www.youtube.com/watch?v=Bz9Lza059NU'
driver.get(path);
time.sleep(60) # Let the user actually see something!
driver.quit()

2 个答案:

答案 0 :(得分:1)

我想出了如何让它发挥作用。这似乎需要两个步骤。将我的默认配置文件复制到某个地方selenium可以使用它,并找出打开chrome时使用的正确标志。密钥是selenium自动添加了一堆我不想要的标志,所以我不得不排除一个。

首先找出我的个人资料的存储位置,我打开了这个网址chrome://version/的chrome。

这给了我很多信息,但重要的是

  

命令行: / usr / lib / chromium-browser / chromium-browser --enable-pinch --flag-switches-begin --flag-switches-end

     

个人资料路径: /home/mdorrell/.config/chromium/Default

首先,我将我的个人资料复制到Selenium可以使用的某个目录

cp -R /home/mdorrell/.config/chromium/Default/* /home/mdorrell/ChromeProfile

然后我在selenium打开的浏览器中打开了同一页面,得到了Command Line行中添加的selenium标志列表。最终给我问题的那个是--disable-default-apps

最后,我需要添加的代码最终看起来像这样

options = webdriver.ChromeOptions()

# Set the user data directory
options.add_argument('--user-data-dir=/home/mdorrell/ChromeProfile')

# get list of flags selenium adds that we want to exclude
excludeList = [
  'disable-default-apps',
]
options.add_experimental_option('excludeSwitches', excludeList)

chromedriverPath = '/my/path/to/chromedriver'
driver = webdriver.Chrome(chromedriverPath, chrome_options=options)

path = 'https://www.youtube.com/watch?v=Bz9Lza059NU'
driver.get(path);
time.sleep(60) # Let the user actually see something!
driver.quit()

答案 1 :(得分:1)

感谢@MikeD分享您的答案。

当我想通过硒浏览器(使用RSelenium)对R Shiny Dashboard进行镀铬时,我遇到了同样的问题。如果我单击Cast,则会显示“ 找不到投射目标。需要帮助吗?”,而从普通浏览器中可以正常运行。

就我而言,它在排除了两个开关(不需要使用ChromeProfile)之后才起作用,在R中可以通过以下操作完成:

library(RSelenium)

options <- list()
options$chromeOptions$excludeSwitches <- list('disable-background-networking',
                                              'disable-default-apps')

rD <- rsDriver(verbose = FALSE, port = 4570L, extraCapabilities = options)