from selenium import webdriver
import time
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome()
driver.implicitly_wait(3)
# 0 .获取网址
driver.get("http://localhost/")
# 1.点击登录
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[1]/div[2]/a[1]").click()
latest_window=driver.window_handles[-1]
driver.close()
driver.switch_to.window(latest_window)
# 2.输入用户名
driver.find_element_by_xpath("//*[@id='username']").send_keys("51testing")
# 3.输入密码
driver.find_element_by_id("password").send_keys("51testing")
# 4.点击登录
driver.find_element_by_class_name("login_btn").click()
# 等待3秒钟
#time.sleep(3)
# 5.点击 进入购物商城
driver.find_element_by_link_text("进入商城购物").click()
# 6.输入关键字
driver.find_element_by_name("keyword").send_keys("iphone")
# 7.点击搜索
driver.find_element_by_class_name("btn1").click()
# 8.点击iPhone查看详情
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[3]/div/div[1]/a/img").click()
# 9 加入购物车
latest_window=driver.window_handles[-1]
driver.close()
driver.switch_to.window(latest_window)
driver.find_element_by_id("joinCarButton").click()
# 10 去购物车结算
driver.find_element_by_class_name("shopCar_T_span3").click()
# 11 结算
driver.find_element_by_class_name("shopCar_btn_03").click()
# 12 添加新地址
driver.find_element_by_class_name("add-address").click()
# 15 填写收货人
driver.find_element_by_name("address[address_name]").send_keys("yifeng")
# 16 填写手机号
driver.find_element_by_name("address[mobile]").send_keys("123456")
# 17 选择城市
sheng=driver.find_element_by_id("add-new-area-select")
Select(sheng).select_by_visible_text("河南省")
city=driver.find_elements_by_class_name("add-new-area-select")[1]
Select(city).select_by_value("410100")
qu=driver.find_elements_by_class_name("add-new-area-select")[2]
Select(qu).select_by_value("410103")
# 18 填写详细地址
driver.find_element_by_name("address[address]").send_keys("人民广场")
# 19 填写邮编
driver.find_element_by_name("address[zipcode]").send_keys("100100")
# 20 点击确定
driver.find_element_by_class_name("aui_state_highlight").click()
selenium+python自动化(完整脚本一)
最新推荐文章于 2024-08-06 17:15:57 发布