#-*- coding:UTF-8 -*-
__author__ = 'poptest'
#考察鼠标滑屏、下拉框
import time
from selenium import webdriver
dr=webdriver.Firefox()
from selenium.webdriver.common.action_chains import ActionChains


def editinfo():
    #点击个人资料
    dr.find_element_by_xpath(".//*[@id='widget_sub_navs']/div/div/ul[3]/li[1]/a").click()
    #修改真实姓名
    dr.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[4]/td[2]/input").send_keys(u"小红")
    #修改性别
    dr.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[5]/td[2]/input[1]").click()
    #修改生日
    dr.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[6]/td[2]/input").send_keys("2016-04-02")
    #填写手机号
    dr.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[7]/td[2]/input").send_keys("18513253584")


    #修改地址
    dr.find_element_by_id("province")
    dr.find_element_by_xpath(".//*[@value='410000']").click()
    dr.find_element_by_id("city")
    dr.find_element_by_xpath(".//*[@value='411400']").click()
    dr.find_element_by_id("county")
    dr.find_element_by_xpath(".//*[@value='411425']").click()

    #填写街道信息
    dr.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[10]/td[2]/textarea").send_keys(u"站集乡")

    #点击修改头像
    #dr.find_element_by_xpath(".//*[@id='upload-link']").click()
    #选择头像
    #dr.find_element_by_xpath(".//*[@id='uploadForm']/p[1]/input").send_keys("poptest$ /Users/poptest/Desktop/a.jpg")
    #点击上传
    #dr.find_element_by_xpath(".//*[@id='upload-btn']").click()
    #time.sleep(2)

    #点击保存
    dr.find_element_by_xpath(".//*[@id='info-form']/table/tbody/tr[11]/td/input").click()


def login():
    #输入邮箱
    dr.find_element_by_xpath(".//*[@id='email']").send_keys("123@qq.com")
    dr.find_element_by_xpath(".//*[@id='content']/div/div/div[2]/form/dl[2]/dd/input").send_keys("111111")
    #点击登录
    dr.find_element_by_xpath(".//*[@id='content']/div/div/div[2]/form/dl[4]/dd/input").click()
    time.sleep(2)

    #鼠标滑屏操作
    time.sleep(2)
    myshop = dr.find_element_by_link_text("我的商城")
    ActionChains(dr).move_to_element(myshop).perform()
    #点击我的消息
    dr.find_element_by_xpath(".//*[@id='header']/div[2]/div/div[3]/dl/dd/ul/li[5]/a").click()
    time.sleep(2)

    editinfo()


def main():
    dr.maximize_window()
    #输入商城网址
    dr.get("http://192.168.114.137/TinyShop/index.php")
    #点击登录
    dr.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[1]/a/b").click()
    time.sleep(2)

    #调用login函数
    login()


main ()