import time
from selenium import webdriver
driver=webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F")
#点击账户登录
driver.find_element_by_link_text("账户登录").click()
#输入用户名和密码
driver.find_element_by_id("loginname").send_keys("15926678892")
driver.find_element_by_id("nloginpwd").send_keys("jj159169")
driver.find_element_by_id("loginsubmit").click()
time.sleep(20)
#手动滑动拼图验证
#搜索框输入内容
driver.find_element_by_id("key").send_keys("洗衣机")
driver.find_element_by_class_name("button").click()
#点击商品图片
driver.find_element_by_css_selector('#J_goodsList > ul > li:nth-child(2) > div > div.p-img > a > img').click()
#页面跳转,切换句柄
new_window=driver.window_handles[-1]
driver.switch_to.window(new_window)
#点击加入购物车
driver.find_element_by_link_text("加入购物车").click()
#点击去购物车结算
driver.find_element_by_id("GotoShoppingCart").click()
#点击去结算
driver.find_element_by_class_name("common-submit-btn").click()
|