selenium(web端)淘寶測試程式碼

chengx_1708發表於2020-10-05
# 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)

相關文章