# coding:utf-8 from selenium import webdriver import time driver = webdriver.Chrome() driver.maximize_window() # 将浏览器最大化显示 # 登录 driver.get("商城url") time.sleep(1) driver.find_element_by_name("username").send_keys("账号") time.sleep(1) driver.find_element_by_name("password").send_keys("密码") driver.find_element_by_name("submit").click() time.sleep(1) driver.get("商城首页url") # 去到首页 # 搜索商品 driver.find_element_by_xpath(".//*[@name='keywords']").click() # 先点击搜索框 driver.find_element_by_xpath(".//*[@name='keywords']").send_keys("爱冕") time.sleep(1) # 点击搜索 driver.find_element_by_xpath(".//*[@type='submit']").click() driver.get("商品的页面url") # 点击加入购物车 time.sleep(1) driver.find_element_by_link_text("加入购物车").click() time.sleep(1) driver.get("购物车页面url") time.sleep(1) driver.find_element_by_xpath(".//*[@type='image']").click() # 点击提交订单 # driver.find_element_by_xpath(".//*[@type='submit']").click() time.sleep(10) driver.quit() # 退出浏览器