[英]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.