zoukankan      html  css  js  c++  java
  • selenium自学笔记---ecshop购买脚本 xpath定位元素(下拉框,单选框)

    本机环境:xamppv3.2.1+ecshop3.0  
    1.元素定位写对,却一直报错,发现是页面元素加载的太慢,所以加上延时


    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()

    # 登陆
    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()
  • 相关阅读:
    启动php-fpm时报错
    安装php时,make test报错
    安装php时,make步骤报错make: *** [sapi/fpm/php-fpm] Error 1
    安装php时,make步骤报错make: *** [ext/gd/gd.lo] Error 1
    运行phpize时出现:Cannot find autoconf. Please check your autoconf installation
    Linux下安装php加速组件XCache
    加速器eaccelerator不兼容高版本php
    Apache下Worker模式MPM参数分析
    Linux SVN直接删除版本库文件
    Linux SVN一次增加多个文件并批量上传
  • 原文地址:https://www.cnblogs.com/fbug/p/6128566.html
Copyright © 2011-2022 走看看