**
selenium(web端)淘宝测试代码
**
# oding = utf-8
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
# 火狐浏览器
web = webdriver.Firefox()
url = "http://www.baidu.com"
web.get(url)
time.sleep(2)
web.find_element_by_xpath(".//*[@id='kw']").send_keys("淘宝官网")
time.sleep(2)
web.find_element_by_id("su").click()
time.sleep(2)
# aaa = web.find_element_by_xpath(".//*[@id='3001']/div[1]/h3/a[1]").click()
# web.switch_to_frame(aaa)
web.find_element_by_link_text(u"淘宝网 - 淘!我喜欢").click()
web.switch_to.window(web.window_handles[1])
time.sleep(2)
web.find_element_by_link_text(u"亲,请登录").click()
time.sleep(2)
web.find_element_by_id("fm-login-id").send_keys(淘宝账号)
time.sleep(2)
web.find_element_by_xpath(".//*[@id='fm-login-password']").send_keys(淘宝密码)
time.sleep(2)
web.find_element_by_xpath(".//*[@id='login-form']/div[4]/button").click()
web.switch_to.window(web.window_handles[1])
time.sleep(2)
# # 0原页面 1代表子页面 2孙页面
# web.switch_to.window(web.window_handles[1])
# 输入淘宝内容
web.find_element_by_id("q").send_keys("狗狗营养膏")
time.sleep(2)
web.find_element_by_xpath(".//*[@id='J_TSearchForm']/div[1]/button").click()
web.switch_to.window(web.window_handles[1])
time.sleep(2)
web.find_element_by_id("J_Itemlist_Pic_43855513193").click()
web.switch_to.window(web.window_handles[2])
time.sleep(2)
# 加入购物车
web.find_element_by_xpath("//a[@id='J_LinkBasket']").click()
time.sleep(2)
# 1,查看购物车
web.find_element_by_xpath("//a[@class='sn-cart-link']").click()
time.sleep(2)
# 删除
web.find_element_by_partial_link_text("删除").click()
time.sleep(2)
web.find_element_by_xpath("//a[@class='dialog-btn J_DialogConfirmBtn']").click()
time.sleep(2)