作者在 2016-04-27 15:37:57 发布以下内容
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'poptest'
import time,unittest
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
class TestAddressModel(unittest.TestCase):
def setUp(self):
global dr
dr = webdriver.Firefox()
dr.get("http://192.168.90.128/tinyshop/")
dr.maximize_window()
def tearDown(self):
dr.quit()
def testAddress(self):
#点击登录
dr.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[1]/a/b").click()
dr.find_element_by_xpath(".//*[@id='email']").send_keys("111@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)
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[6]/a").click()
#添加新地址
dr.find_element_by_xpath(".//*[@id='address_other']").click()
#引入iframe界面
frame = dr.find_element_by_xpath("/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div/iframe")
iframe = dr.switch_to_frame(frame)
pro = dr.find_element_by_id("province")
pro.find_element_by_xpath(".//*[@value='110000']").click()
city = dr.find_element_by_id("city")
city.find_element_by_xpath(".//*[@value='110100']").click()
cou = dr.find_element_by_id("county")
cou.find_element_by_xpath(".//*[@value='110101']").click()
#邮编
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[2]/td[2]/input").send_keys("100000")
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[3]/td[2]/textarea").send_keys(u"北京市东城区东单三条")
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[4]/td[2]/input").send_keys(u"小红")
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[5]/td[2]/input").send_keys("18513253584")
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[8]/td/input").click()
if __name__ == '__main__':
unittest.main()