本机环境:xamppv3.2.1+ecshop3.0 1.元素定位写对,却一直报错,发现是页面元素加载的太慢,所以加上延时 from selenium import webdriverimport timedriver=webdriver.Chrome()driver.implicitly_wait(10) #自动延时10sdriver.get("http://localhost/ecshop")# 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()
时间: 2024-10-25 08:42:10