简体   繁体   English

如何最小化启动Selenium Firefox Web浏览器?

[英]How to start a Selenium Firefox web browser minimized?

My python script is in a loop and runs every half an hour, when ever the code runs it opens Firefox browser. 我的python脚本处于循环中,每半小时运行一次,只要代码运行,它将打开Firefox浏览器。 So if I am working/ looking at any other screen all of a sudden the browser window pops up. 因此,如果我正在工作/正在查看其他屏幕,突然会弹出浏览器窗口。 I want my browser to either start minimized or disappear but my code should execute 我希望浏览器启动最小化或消失,但是我的代码应该执行

while(True):
    driver = webdriver.Firefox()
    driver.get("http://iiitb.campusmetalink.com/cml/pages/setup/ModuleHome.jsf")
    driver.find_element_by_name("recqIDId:j_id15").send_keys("IIITB")
    driver.find_element_by_name("recqIDId:j_id17").send_keys("username")
    driver.find_element_by_name("recqIDId:j_id19").send_keys("password")
    driver.find_element_by_name("recqIDId:j_id25").click()
    WebDriverWait(driver, 100)
    driver.find_element_by_xpath('//*[@id="moduleForm:j_id40_body"]/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr[6]/td[2]/a').click()
    driver.find_element_by_xpath('//*[@id="scheduleForm:coltrm"]').send_keys("2016TERM2")
    driver.find_element_by_xpath('//*[@id="scheduleForm:search"]').click()
    elements = driver.find_elements_by_xpath('//*[@id="scheduleForm:svres:tb"]/tr')
    if( len(elements) > 6):
        os.system("C:/wamp64/bin/php/php5.6.16/php C:/wamp64/www/srishti/space_auth/Source/Source_code/public/mail_includes.php")
    print elements
    driver.close()
    time.sleep(1800)

While Selenium does provide an inbuilt function to maximize the window, unfortunately it doesn't provide the same functionality to minimize the window. 尽管Selenium确实提供了使窗口最大化的内置功能,但不幸的是,它没有提供使窗口最小化的相同功能。

The below code will move the browser window out of sight, but I don't know if this will fulfil your requirements. 下面的代码将使浏览器窗口不可见,但是我不知道这是否可以满足您的要求。

driver.set_window_position(0, 0)

Unfortunately selenium webdriver does not provide any built in function to minimize the window . 不幸的是,硒webdriver没有提供任何内置功能来最小化窗口。 However you can position your window out of sight by using below code. 但是,您可以使用以下代码将窗口置于看不见的位置。 driver.manage().window().setPosition(new Point(-2000, 0)); driver.manage()。window()。setPosition(new Point(-2000,0));

As other people already said: selenium webdriver does not provide any built in function to minimize the window BUT there are few roundabouts way to do it. 正如其他人已经说过的:硒webdriver不提供任何内置功能来最小化窗口,但是很少有回旋的方式来做到这一点。 One of my favourite way is using win32gui and win32con: 我最喜欢的方法之一是使用win32gui和win32con:

import win32gui, win32con
win32gui.ShowWindow(win32gui.GetForegroundWindow(), win32con.SW_MINIMIZE)

The bad side of this code is, that the browser must be on the foreground. 此代码的缺点是,浏览器必须位于前台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 selenium python 中最小化打开浏览器 window? - How to open browser window as minimized in selenium python? Python : Selenium 不启动 firefox 浏览器 - Python : Selenium does not start the firefox browser 如何在浏览器最小化时使用 selenium webdriver 执行测试 - How to execute tests with selenium webdriver while browser is minimized Selenium,如何使用插件启动 Firefox? - Selenium, how to start Firefox with addons? Webdriver Selenium中是否存在浏览器最大化的模式,而实际上却最小化了? - Is there 'as if' maximized mode of browser in Webdriver Selenium, but in reality minimized? 启动 Selenium 铬驱动程序最小化(或等效) - start Selenium chrome driver minimized (or equivalent) 如何在线程期间关闭 web 浏览器以及如何在 Python Selenium Firefox 中的计时器上设置线程? - How to close web browser during thread and how to set thread on a timer in Python Selenium Firefox? 如何使用 selenium python 启动 Firefox 浏览器 - How to launch Firefox browser using selenium python 如何将 Selenium 连接到现有的 Firefox 浏览器? (Python) - How to connect Selenium to existing Firefox browser? (Python) 如何获得 Selenium (Firefox) 的无头浏览器? - How to Get a Headless Browser for Selenium (Firefox)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM