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

时间:2013-12-24 12:56:17

标签: 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 exists" 

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

    code:3
    ------
    body.send_keys("{%" "n}")

没有什么对我有用我想在运行时或调用后最小化我的firefox窗口

或以无焦点的隐形模式运行

1 个答案:

答案 0 :(得分:-1)

以下代码应该有所帮助:

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()