Selenium Python 致友自动登陆

来源:互联网 发布:软件测试研究 编辑:程序博客网 时间:2024/04/30 11:51
Selenium Python 致友自动登陆
发布于:2013-10-12 15:48:36

@沈佳龙

显然Python的效率更高啊~

#simple Example For Selenium By Python
#_*_ coding:UTF-8 _*_

__author__ = 'archer

from selenium import webdriver
from selenium.common.exceptions import *
import time

class SomeTest(object):

        def __init__(self):
            pass

        def myfirsttest(self,myurl):

            'start url'
            browser=webdriver.Firefox()
            browser.get(myurl)

            'Start to Find a element'
            try:
                myemail=browser.find_element_by_id('email')
                mypass=browser.find_element_by_id('password')
                myloginbutton=browser.find_element_by_class_name('login-submit')

            except NoSuchElementException:

                assert 0,'找不到元素'

            else:

                myemail.send_keys('gongtianyu@kedacom.com')
                mypass.send_keys('**********')
                myloginbutton.click()

                time.sleep(2)


if __name__=='__main__':

    mytest=SomeTest()
    mytest.myfirsttest('http://weibo.kedacom.com')

0 0
原创粉丝点击