本文介绍了在Python中最大化WebDriver(Selenium 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个简单的脚本,该脚本检查我是否有任何标有SOMETHING的gmail电子邮件,然后在登录页面中打开Firefox浏览器窗口,然后转到其他页面.

I'm attempting to write a simple script that checks if I have any gmail emails labeled SOMETHING and then opens a firefox browser window to a login page, after which it goes to something else.

这就是我在做什么:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
import time, imaplib

Eusername = "[email protected]"
Epassword = "password1"

username = "username"
password = "password2"

imaps = imaplib.IMAP4_SSL('imap.gmail.com','993')
imaps.login(Eusername,Epassword)

imaps.select('SOMETHING')
status, response = imaps.status('SOMETHING', "(UNSEEN)")
unreadcount = int(response[0].split()[2].strip(').,]'))

while unreadcount > 0:
    driver = webdriver.Firefox()
    driver.get('http://wwww.SomeURL.com/some_login.html')
    time.sleep(3)
    inputElement = driver.find_element_by_name("user")
    inputElement.send_keys(username)
    inputElement = driver.find_element_by_name("pw")
    inputElement.send_keys(password)
    inputElement.submit()
    time.sleep(1)
    driver.get('http://www.SomeURL.com/somethingelse.html')
    imaps.select('SOMETHING')
    typ ,data = imaps.search(None,'UnSeen')
    imaps.store(data[0].replace(' ',','),'+FLAGS','\Seen')

我花了数小时进行搜索,但没有找到最大化浏览器窗口的解决方案.在其他地方,我已经读到有一个windowMaximize()或window_maximize(),但是由于我尝试过的每种配置都声称对于任何模块都不存在,因此无法使其正常工作.

I've spent hours search and haven't found a solution to maximize the browser window. Elsewhere i've read that there is a windowMaximize() or window_maximize(), but have not been able to get them to work since every configuration I've tried claims it doesn't exist for whatever module.

我只知道一点点python,并且正在Mac OSX中工作

I only know a little python, and am working in Mac OSX

推荐答案

我以前从未使用过此功能,所以我尝试了.

I've never used this functionality before, so I tried it out.

driver.maximize_window()

这似乎很好用-除非我使用的是Chrome.我不确定这是否有缺陷,因为它可以在IE9和Firefox中完美运行.

This seems to work fine - unless I am using Chrome. I'm not sure if this is a defect, as it works flawlessly in IE9 and Firefox.

此功能尚未在Chromedriver -=发行链接=-

edit:This is a feature which has yet to be implemented in Chromedriver -= Link to issue =-

这篇关于在Python中最大化WebDriver(Selenium 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!