【问题标题】:Full screen Firefox Python Selenium全屏 Firefox Python Selenium
【发布时间】:2017-02-04 22:41:28
【问题描述】:

我正在尝试在 Python 3 中使用 Selenium 在 Firefox 中启动全屏页面。页面打开工作正常,但是当我将 F11 键发送到浏览器时(Full屏幕键),任何事情都会发生。这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

firefox = webdriver.Firefox()
firefox.get('http://localhost')
firefox.maximize_window()

body = firefox.find_element_by_tag_name('html')
body.send_keys(Keys.F11)

有人知道如何让我的页面全屏启动吗?我知道 Chrome 可以,但 Firefox 更难

【问题讨论】:

    标签: python selenium firefox


    【解决方案1】:

    这对我有用。

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    driver = webdriver.Firefox()
    
    driver.get('http://localhost')
    driver.find_element_by_xpath('/html/body').send_keys(Keys.F11)
    

    希望对你有帮助

    刚刚意识到我使用的是 Python 2.6 而不是你的 3。对此很抱歉,但至少你知道它可以在较旧的 Python 版本上运行

    【讨论】:

      【解决方案2】:

      pip3 安装 selenium pyautogui

      #!/usr/bin/env python3
      import pyautogui
      from selenium import webdriver
      profile = webdriver.FirefoxProfile()
      profile.set_preference("dom.webnotifications.enabled", False)
      profile.set_preference("general.useragent.override", "Mozilla/5.0")
      profile.update_preferences()
      browser = webdriver.Firefox(firefox_profile=profile,executable_path = '/usr/local/bin/geckodriver')
      browser.get("https://www.screenku.com")
      pyautogui.press('f11')
      

      【讨论】:

        【解决方案3】:

        Selenium 有一个内置方法可以使窗口全屏:fullscreen_window()

        Selenium API - fullscreen_window()

        调用特定于窗口管理器的“全屏”操作

        browser.get("https://www.screenku.com")
        browser.fullscreen_window()
        

        【讨论】:

          猜你喜欢
          • 2021-06-08
          • 1970-01-01
          • 2013-09-14
          • 2016-03-10
          • 2022-08-14
          • 1970-01-01
          • 2015-05-04
          • 2013-12-25
          • 2011-09-24
          相关资源
          最近更新 更多