python train1

作者在 2016-03-25 15:43:53 发布以下内容
#-*- coding:UTF-8 -*-  # 解码方式
__author__ = 'pop'

from selenium import webdriver  #
import time
def testLogin(testname,testpassword,repass,revtype,realvalue):

    bruce = webdriver.Firefox()   #start firfox brower .bruce定义为火狐浏览器
    bruce.maximize_window()    # max windows
    bruce.get("http://192.168.242.128:8088/Tinyshop/")   # url
    time.sleep(3)
    bruce.find_element_by_link_text("注册").click()
    bruce.find_element_by_id("email").send_keys(testname)
    bruce.find_element_by_name("password").send_keys(testpassword)
    bruce.find_element_by_name("repassword").send_keys(repass)
    bruce.find_element_by_name("verifyCode").send_keys("1111")
    bruce.find_element_by_id("readme").click()
    bruce.find_element_by_class_name("btn").click()
    #actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div/div[1]").text
    actvalue = bruce.find_element_by_xpath(revtype).text
    #print actvalue

   #bruce.implicitly_wait(3)
    if realvalue == actvalue:

        print "ok"

    else:

        print "suck my dick"
    time.sleep(3)
    bruce.close()

testLogin("55464683","123456","123456",".//*[@id='content']/div/div/div[1]",u"邮箱(例如:demo@tinyx.com)")
# 输入邮箱格式不正确

testLogin("554646832@qq.com","123456","123456",".//*[@id='content']/div/div/div[1]",u"恭喜您,注册成功!")
#用户注册成功

testLogin("554646829@qq.com","123456","123456",".//*[@id='content']/div/div[1]/div[2]/form/dl[1]/dd/label",u"此用户已经注册")
#此用户已经注册
time.sleep(2)

testLogin("5546@qq.com","","",".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/label",u"6-20任意字符组合")
#密码为空
time.sleep(2)

testLogin("5546@qq.com","12345","12345",".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/label",u"6-20任意字符组合")
#密码不为6位数
time.sleep(2)

testLogin("5546@qq.com","123456789012345678901","123456789012345678901",".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/label",u"6-20任意字符组合")
#密码超20位数,为21位

testLogin("5543242@qq.com","123456","1234567",".//*[@id='content']/div/div[1]/div[2]/form/dl[3]/dd/label",u"两次输入密码不一致")
#两次密码不一致
#-*- coding:UTF-8 -*-  # 解码方式
__author__ = 'pop'

from selenium import  webdriver
import sys
def findnextpage1():
    lee.find_element_by_xpath(".//*[@id='pagination']/ul/li[14]/a").click()
    for i in range(1,11):
        title = lee.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/h3/span").text
        if title == u"100起投,长兴8号337-5":
            label = lee.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/div[2]/p[1]/em").text
            print  label
            sys.exit()
        else:
            print "suck"
    findnextpage1()

def findonepage():
    global lee
    global title
    lee = webdriver.Firefox()
    lee.maximize_window()
    lee.get("http://www.firstp2p.com/deals?cate=16")

    for i in range(5,11):
        title = lee.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/h3/span").text
        if title == u"100起投,长兴8号337-5":
            label = lee.find_element_by_xpath("html/body/div[1]/section/div/div[2]/div/div[1]/div["+str(i)+"]/div/div[1]/div[2]/p[1]/em").text
            print  label
            break
        else:
            print "suck"
    findnextpage1()
findonepage()
#-*- coding:UTF-8 -*-  # 解码方式
__author__ = 'poptest'
import time
from  selenium import webdriver
from  selenium.webdriver.common.action_chains import ActionChains
sd = webdriver.Firefox()
def editinfo():

         time.sleep(2)
         sd.find_element_by_xpath(".//*[@id='widget_sub_navs']/div/div/ul[3]/li[1]/a").click()
         time.sleep(1)
         sd.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[5]/td[2]/input[1]").click() #
         time.sleep(1)
         sd.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[6]/td[2]/input").send_keys("1989-05-26")

         time.sleep(2)



         #对下拉框的操作

         #sd.find_element_by_xpath(".//*[@id='province']").click()

         pro = sd.find_element_by_id("province")   #gei sheng dingyi

         allProOptions = pro.find_elements_by_tag_name("option")   #gei zhi dingyi

         for tmpPro in allProOptions:

             tmpNum1 = tmpPro.get_attribute("value")

             if tmpNum1 == "140000":

                 tmpPro.click()

                 pro2 = sd.find_element_by_id("city")   #gei shi dingyi

                 allProOptions1 = pro2.find_elements_by_tag_name("option")  #zhao shi zhi

                 for tmpPro2 in allProOptions1:

                     tmpNum2 = tmpPro2.get_attribute("value")

                     if tmpNum2 == "140200":

                        tmpPro2.click()

                        pro3 = sd.find_element_by_id("county")   #gei shi dingyi

                        allProOptions3 = pro3.find_elements_by_tag_name("option")  #zhao shi zhi

                        for tmpPro3  in allProOptions3:

                            tmpNum3 = tmpPro3.get_attribute("value")

                            if  tmpNum3 == "140211":

                                tmpPro3.click()

         #changeinfo
         time.sleep(2)
         sd.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[4]/td[2]/input").send_keys("fuck")
         sd.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[7]/td[2]/input").send_keys("15555555555")
         sd.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[10]/td[2]/textarea").send_keys("shanxidatong")
         time.sleep(2)
         #上传图片
         sd.find_element_by_id("upload-link").click()

         sd.find_element_by_xpath(".//*[@id='uploadForm']/p[1]/input").send_keys("/Users/poptest/Desktop/outofmyhome.jpg ")
         sd.find_element_by_id("upload-btn").click()

         sd.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[11]/td/input").click()

def login():
    sd.find_element_by_id("email").send_keys("a@a.com")
    sd.find_element_by_name("password").send_keys("111111")
    sd.find_element_by_xpath(".//*[@id='content']/div/div/div[2]/form/dl[4]/dd/input").click()

    #鼠标滑屏操作
    myshop = sd.find_element_by_xpath(".//*[@id='header']/div[2]/div/div[3]/dl/dt/a")
    ActionChains(sd).move_to_element(myshop).perform()
    sd.find_element_by_xpath(".//*[@id='header']/div[2]/div/div[3]/dl/dd/ul/li[5]/a").click()
    editinfo()

def brows():

    sd.maximize_window()
    sd.get("http://192.168.242.128:8088/Tinyshop/")
    time.sleep(1)
    sd.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[1]/a/b").click()
    login()    #调用login函数

brows()

python | 阅读 11874 次
文章评论,共0条
游客请输入验证码
浏览2342081次