gpt4 book ai didi

python - 全屏 Firefox Python Selenium

转载 作者:行者123 更新时间:2023-12-01 03:19:29 24 4
gpt4 key购买 nike

我正在尝试使用 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 就更难了

最佳答案

这对我有用。

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 版本上运行

关于python - 全屏 Firefox Python Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42046471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com