Python 2.7 (Python、Selenium)如何在运行时最小化firefox窗口

Python 2.7 (Python、Selenium)如何在运行时最小化firefox窗口,python-2.7,selenium-webdriver,Python 2.7,Selenium Webdriver,如何使用selenium和python最小化firefox窗口 我试过了 try: body=None body = driver.find_element_by_tag_name("body") body.send_keys("{%+" "+N}") print "entered keys" except NoSuchElementException: print "item body is not

如何使用selenium和python最小化firefox窗口

我试过了

    try:
        body=None
        body = driver.find_element_by_tag_name("body")
        body.send_keys("{%+" "+N}")
        print "entered keys"
    except NoSuchElementException:
        print "item body is not exists" 

    code:2
    ------
    body.send_keys(Keys.CONTROL+Keys.ESCAPE+'D')

    code:3
    ------
    body.send_keys("{%" "n}")
对我来说没有任何效果我想在运行或调用firefox后最小化我的firefox窗口


或者在无焦点的不可见模式下运行,以下代码应该会有所帮助:

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

driver = webdriver.Firefox()
driver.get("http://www.google.com")
actionChain = ActionChains(driver).key_down(Keys.ALT)
actionChain.send_keys(Keys.SPACE)
actionChain.send_keys("n")
actionChain.perform()

当运行上面的代码时,它只是保持空闲…有人能帮我最小化吗browser@VikasNeha Ojha,你的代码在IE和FireFox上不起作用;最好在提交答案之前测试代码。