作者在 2016-03-25 15:52:30 发布以下内容
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'poptest'
import time
from selenium import webdriver
sh = webdriver.Firefox()
from selenium.webdriver.common.action_chains import ActionChains
def editinfor():
#点击收货地址
#sh.find_element_by_xpath(".//*[@id='header']/div[2]/div/div[3]/dl/dd/ul/li[5]/a").click()
#点击添加新地址
sh.find_element_by_xpath(".//*[@id='address_other']").click()
#引入iframe界面
frame = sh.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 = sh.switch_to_frame(frame)
#添加信息
pro = sh.find_element_by_id("province")
pro.find_element_by_xpath(".//*[@value='110000']").click()
city = sh.find_element_by_id("city")
city.find_element_by_xpath(".//*[@value='110100']").click()
cou = sh.find_element_by_id("county")
cou.find_element_by_xpath(".//*[@value='110101']").click()
#输入邮政编码
sh.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[2]/td[2]/input").send_keys("100000")
#输入街道地址
sh.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[3]/td[2]/textarea").send_keys(u"北京市东城区东单3条")
#输入收货人姓名
sh.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[4]/td[2]/input").send_keys(u"小红帽")
#输入手机号码
sh.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[5]/td[2]/input").send_keys("13613552859")
#点击勾选
sh.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[7]/td[2]/input").click()
#点击提交查询
sh.find_element_by_xpath(".//*[@id='address-form']/table/tbody/tr[8]/td/input").click()
time.sleep(3)
sh.close()
def login():
time.sleep(2)
sh.find_element_by_id("email").send_keys("554646831@qq.com")
sh.find_element_by_name("password").send_keys("123456")
time.sleep(2)
sh.find_element_by_xpath(".//*[@id='content']/div/div/div[2]/form/dl[4]/dd/input").click()
#鼠标滑屏操作
time.sleep(2)
myshop = sh.find_element_by_link_text("我的商城")
ActionChains(sh).move_to_element(myshop).perform()
#点击收货地址
sh.find_element_by_xpath(".//*[@id='header']/div[2]/div/div[3]/dl/dd/ul/li[6]/a").click()
editinfor()
def brows():
sh.maximize_window()
sh.get("http://172.16.129.135:80/Tinyshop/")
time.sleep(2)
sh.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[1]/a/b").click()
login() #调用login函数
brows()
#-*- coding:utf-8 -*-
__author__ = 'poptest'
import time
from selenium import webdriver
sd = webdriver.Firefox()
sd.get("http://www.12306.cn/mormhweb/")
sd.maximize_window()
sd.find_element_by_xpath(".//*[@id='fmsearch']/input[3]").click()
st = sd.switch_to_alert().text #定义
if st == u"请输入搜索条件":
print "same"
sd.switch_to_alert().accept()
else:
print "not same"
sd.switch_to_alert().accept() # JavaScript弹框进行操作,相当于确认
time.sleep(1)
sd.close()
#-*- coding:utf-8 -*-
__author__ = 'poptest'
import time
from selenium import webdriver
def suck():
sd = webdriver.Firefox()
sd.maximize_window()
sd.get("https://kyfw.12306.cn/otn/leftTicket/init")
sd.find_element_by_id("wf").click()
sd.find_element_by_id("fromStationText").click() #单机下拉框
sd.find_element_by_xpath(".//*[@id='nav_list2']").click() #单击第一个出发地栏
time.sleep(1)
sd.find_element_by_xpath(".//*[@id='flip_cities2']/a").click() # 完成下一页的动作
time.sleep(1)
sd.find_element_by_xpath(".//*[@id='flip_cities2']/a[2]").click()
time.sleep(1)
sd.find_element_by_xpath(".//*[@id='ul_list2']/li[27]").click() #选择大同
time.sleep(2)
sd.find_element_by_id("toStationText").click() #单机目的地栏
sd.find_element_by_xpath(".//*[@id='ul_list1']/li[1]").click() #选择北京
time.sleep(2)
str = "document.getElementById('train_date').readonly=false" #修改属性值,去掉只读属性
strdate = "document.getElementById('train_date').value=\'2016-03-09\'" # 把预定日期填进去
sd.execute_script(str)
sd.execute_script(strdate)
str1 = "document.getElementById('back_train_date').readonly=false"
strdate1 = "document.getElementById('back_train_date').value=\'2016-03-12\'"
sd.execute_script(str1)
sd.execute_script(strdate1)
time.sleep(2)
sd.find_element_by_id("query_ticket").click()
suck()
#-*- coding:utf-8 -*-
__author__ = 'poptest'
from selenium import webdriver
import time
import sys
def suck():
shi = webdriver.Firefox()
shi.maximize_window()
shi.get("http://www.12306.cn/mormhweb/")
cuhandle = shi.current_window_handle # 定义当前窗口句柄
shi.find_element_by_xpath(".//*[@id='newLeft']/div[3]/a/img").click()
time.sleep(2)
handle = shi.window_handles #所以打开窗口的句柄
for secpage in handle:
if secpage != cuhandle:
shi.switch_to_window(secpage)
shi.find_element_by_link_text(u"1、铁路旅客服务质量调查问卷").click()
# shi.maximize_window()
time.sleep(2)
sys.exit
handle = shi.window_handles
for thrpage in handle:
secpage = shi.current_window_handle
if thrpage != cuhandle and thrpage != secpage:
shi.switch_to_window(thrpage)
time.sleep(2)
shi.find_element_by_xpath(".//*[@id='agree']/span").click()
# shi.maximize_window()
time.sleep(2)
shi.find_element_by_xpath(".//*[@id='close']").click()
shi.quit()
suck()