Selenium self-study note---ecshop Purchase script XPath anchor element (drop-down box, radio box)

Source: Internet
Author: User
Tags xpath

Native Environment: xamppv3.2.1+ecshop3.0
1. Element positioning write right, but has been error, found that the page element loading is too slow, so add delay


From selenium import Webdriver
Import time
Driver=webdriver. Chrome ()
Driver.implicitly_wait (10)

#自动延时10s
Driver.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 ()

# Login
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 ()
# Select a product
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 ()

#选择城市 drop-down box 1. Two-time positioning 2.xpath positioning level label
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 = ']"). Click ()

Driver.find_element_by_xpath ("//select[@name = ' District ']/option[3]"). Click ()

driver.find_element_by_id ("Consignee_0"). Send_keys (' Zhang San ')
driver.find_element_by_id ("Address_0"). Send_keys ("Shenzhen Baoan District")
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 ()

Selenium self-study note---ecshop Purchase script XPath anchor element (drop-down box, radio box)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.