# I'm sure this will be interchangeable with the Chrome driver too
driver = webdriver.Firefox()
# Set the focus to the browser rather than the web content
driver.set_context("chrome")
# Create a var of the window
win = driver.find_element_by_tag_name("window")
# Send the key combination to the window itself rather than the web content to zoom out
# (change the "-" to "+" if you want to zoom in)
win.send_keys(Keys.CONTROL + "-")
# Set the focus back to content to re-engage with page elements
driver.set_context("content")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.implicitly_wait(5)
driver.get("https://stackoverflow.com/")
# Set the focus to the browser rather than the web content
driver.set_context("chrome")
# Create a var of the window
win = driver.find_element(By.TAG_NAME,"html")
# for zoom out this will change to 90% if you need more copy and paste it again. Or you can change - to + for zoom in.
win.send_keys(Keys.CONTROL + "-")
# Set the focus back to content to re-engage with page elements
driver.set_context("content")
5条答案
按热度按时间flvlnr441#
在指定缩放级别时,可以执行类似的操作,如下所示:
例如,如果我的
body
有一个<div id='values'>
,我可以使用或者干脆试一试:
w51jfk4q2#
这将为使用Selify(-v 3.141.0)的Python完成此工作
8nuwlpux3#
我也在到处寻找使用Selify缩小的解决方案,但文档没有提到任何内容。幸运的是,Firefox的驱动程序(gecko驱动程序)在他们的Github issues上有这个
我已经对如何缩小(和放大)做了一个简略的说明,希望这将是最有意义的(或者至少对我来说是这样)
kulphzqa4#
这适用于IE
y1aodyip5#
嘿,伙计们,我对使用Firefox的所有解决方案都有问题,有些解决方案没有完全像预期的那样工作,所以在你们的帮助下,我创建了这个解决方案。