作者在 2016-04-03 14:40:46 发布以下内容
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'poptest'
#考察iframe框架
import time
from selenium import webdriver
#打开火狐浏览器
dr = webdriver.Firefox()
from selenium.webdriver.common.action_chains import ActionChains
#窗口最大化
dr.maximize_window()
def editinfor():
#点击添加新地址
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"北京市东城区东单3条")
#输入收货人姓名
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("18531253584")
#点击勾选
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[7]/td[2]/input").click()
#点击提交查询
dr.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[8]/td/input").click()
dr.close()
def login():
time.sleep(2)
dr.find_element_by_id("email").send_keys("123@qq.com")
dr.find_element_by_name("password").send_keys("111111")
time.sleep(2)
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()
time.sleep(2)
editinfor()
def main():
dr.get("http://192.168.114.137/Tinyshop")
time.sleep(2)
dr.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[1]/a/b").click()
login() #调用登录函数
main()