[英]Full screen Firefox Python Selenium
I'm trying to start a full screen page in Firefox with Selenium in Python 3. The page opening works fine, but when I send the F11 key to the browser (the Full Screen key), anything happens.我正在尝试使用 Python 3 中的 Selenium 在 Firefox 中启动全屏页面。页面打开工作正常,但是当我将F11键发送到浏览器(全屏键)时,任何事情都会发生。 Here is my code :
这是我的代码:
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)
Does anyone know how to make my page start in full screen ?有谁知道如何让我的页面全屏启动? I know it's possible with Chrome, but it's harder with Firefox
我知道 Chrome 可以,但 Firefox 更难
This is what worked for me. 这对我有用。
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)
Hope this helps 希望这可以帮助
Just realized I am using Python 2.6 vs your 3. Sorry about that, but at least you know it will work on an older Python version 刚刚意识到我使用的是Python 2.6与您的3。抱歉,但是至少您知道它可以在较旧的Python版本上运行
pip3 install selenium pyautogui pip3安装硒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')
Selenium has a built-in method to make the window fullscreen: fullscreen_window()
Selenium 有一个使窗口全屏的内置方法:
fullscreen_window()
Selenium API - fullscreen_window() Selenium API - fullscreen_window()
Invokes the window manager-specific 'full screen' operation
调用特定于窗口管理器的“全屏”操作
browser.get("https://www.screenku.com")
browser.fullscreen_window()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.