qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Selenium实例:Python登录WebQQ

 selenium范例:python登录webqq
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
from pprint import pprint
username="username"
passwd="password"
class WebQQ:
def __init__(self):
self.browser = webdriver.Firefox() # Get local session of firefox
self.browser.set_window_position(800,0)
self.browser.get("http://web.qq.com") # Load page
while True:
try:
elem = self.browser.find_element_by_id("alloy_icon_app_50_3") # Find the qq button
elem.click()
print "click qq button"
break
except NoSuchElementException:
print "element not loaded yet"
time.sleep(0.1) # Let the page load, will be added to the API
def login(self):
self.browser.switch_to_frame("ifram_login")
# Find the loginState option
elem = self.browser.find_element_by_id("loginState")
elem.click()
print "click loginState"
# choose hidden state
elem = self.browser.find_element_by_id("loginStatePanel")
elems = elem.find_elements_by_class_name("statePanel_li")
elems[0].click()
print "choose online state"
# login
elem = self.browser.find_element_by_id("u") # user name
elem.send_keys(username)
elem = self.browser.find_element_by_id("p") # passwd
elem.send_keys(passwd)
elem = self.browser.find_element_by_id("login_button") # login button
elem.click()
def main():
webqq = WebQQ()
webqq.login()
if __name__ == "__main__":
main()

posted on 2014-03-27 17:04 顺其自然EVO 阅读(717) 评论(0)  编辑  收藏 所属分类: selenium and watir webdrivers 自动化测试学习


只有注册用户登录后才能发表评论。


网站导航:
 
<2014年3月>
2324252627281
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜