您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程

ecshop购买脚本xpath定位元素(下拉框,单选框)

南春2025-02-12 17:52:33ecshop商城教程已有13人查阅

导读本机环境:xamppv3.2.1+ecshop3.01.元素定位写对,却一直报错,发现是页面元素加载的太慢,所以加上延时from selenium import webdriverimport timedriver=webdriver.Chrome()

本机环境:xamppv3.2.1+ecshop3.0
1.元素定位写对,却一直报错,发现是页面元素加载的太慢,所以加上延时
from selenium import webdriver
import time
driver=webdriver.Chrome()
driver.implicitly_wait(10)
#自动延时10s
driver.get("")
# driver.find_element_by_xpath('//div[@class="fl cart-yh"]/a').click()
driver.find_element_by_xpath("//a[@href='user.php']").click()
# 登陆
driver.find_element_by_name("username").send_keys("zach")
driver.find_element_by_name('password').send_keys("123456")
driver.find_element_by_name("submit").click()
# 选择商品
time.sleep(3)
driver.find_element_by_xpath("//img[@src='images/201605/thumb_img/72_thumb_G_1462956048008.jpg']").click()
driver.find_element_by_xpath("//img[@src='themes/default/images/buybtn1.png']").click() #立即购买
# driver.find_element_by_xpath("/html/body/div[6]/div[1]/table/tbody/tr/td[2]/a/img").click() #结算
driver.find_element_by_xpath("//img[@src='themes/default/images/checkout.gif']").click()
#选择城市 下拉框 1.两次定位 2.xpath 定位层级标签
province = driver.find_element_by_name("province")
province.find_element_by_xpath("//option[@value='5']").click()
city = driver.find_element_by_id("selCities_0")
city.find_element_by_xpath("//option[@value='50']").click()
driver.find_element_by_xpath("//select[@name='district']/option[3]").click()
driver.find_element_by_id("consignee_0").send_keys('张三')
driver.find_element_by_id("address_0").send_keys("深圳市宝安区")
driver.find_element_by_id("tel_0").send_keys("18888888888")
driver.find_element_by_class_name("bnt_blue_2").click()
#付款
time.sleep(3)
driver.find_element_by_xpath("//input[@name='shipping' and @value='5']").click()
driver.find_element_by_xpath("//*[@id='paymentTable']/tbody/tr[4]/td[1]/input").click()
driver.find_element_by_xpath("//input[@src='themes/default/images/bnt_subOrder.gif']").click()

本文标签:

很赞哦! (0)

暂无内容
暂无内容
暂无内容
暂无内容
留言与评论 (共有 0 条评论)
昵称:
匿名发表 登录账号
         
验证码: