zoukankan      html  css  js  c++  java
  • python selenium chrome 测试

    #coding=utf-8
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.by import By
    from time import sleep
    
    def  search(driver, main_material_code):
        autocompelete_input(driver, "vwMaterialForStandBy2_MainMaterial_search1", main_material_code)    
        btnfind = driver.find_element_by_link_text("查询")    
        btnfind.click() 
        
    
    def autocompelete_input(cd, name, input_str):
        iu_main = cd.find_element_by_id(name)    
        iu = iu_main.find_element(by=By.CLASS_NAME,value="mini-buttonedit-input")    
        iu.clear()
        iu.send_keys(input_str)
        sleep(1)
        iu.send_keys(Keys.ENTER)
        iu.send_keys(Keys.ENTER)
    
    def grid_input(cd, str):            
        zlist = cd.find_elements_by_class_name("mini-grid-editwrap")
        print("数量:")
        print(len(zlist))
        zlast_el = len(zlist) - 1
        input = zlist[zlast_el].find_element(by=By.CLASS_NAME ,value="mini-buttonedit-input")
        input.send_keys(str)
        sleep(1)
        input.send_keys(Keys.ENTER)
        input.send_keys(Keys.ENTER)
              
    
    
    options = webdriver.ChromeOptions()
    options.add_argument("--start-maximized")
    options.add_argument("disable-infobars")
     
    driver = webdriver.Chrome(chrome_options=options)
    driver.implicitly_wait(30)
    #driver.maximize_window()
    driver.get("http://192.168.0.1")
     
     
    driver.find_element_by_id("txtName").send_keys("test")
    driver.find_element_by_id("txtPassword").send_keys("123")
    driver.find_element_by_id("BtnLogin").click()
     
     
    driver.find_element_by_link_text("data").click()
    driver.find_element_by_link_text("backup").click()
    
    sleep(4)
    
    
    frame = driver.find_element(by="id",value="main")
    driver.switch_to.frame(frame)
    product_list = ["F-1", "F-2"]
    material_list = ["E-1", "E-2", "E-3"]
    
    
    btnfind = driver.find_element_by_link_text("查询")
    btndel = driver.find_element_by_link_text("删除")
    
    
    
    driver.find_element_by_id("collapse_search_button").click()
    
    
    
    search(driver, material_list[0])
    
    sleep(2)
    
    rows = driver.execute_script("return vwMaterialForStandBy_datagrid2.data.length;")
    
    sleep(1)
    print("行数:" + str(rows))
    if rows >0 :
        driver.execute_script("vwMaterialForStandBy_datagrid2.selectAll(true);")       
        sleep(1)
        btndel.click()
        sleep(1)
        driver.find_element_by_class_name("mini-messagebox-buttons").find_element(by=By.XPATH ,value="//*[text()='确定']").click()                           
        print("删除了")
    
    
    driver.find_element_by_id("vwMaterialForStandBy2_btnadd").click()
    sleep(1)
    btnadd = driver.find_element_by_id("btnadd_productcode_item")
    for item in product_list:
        btnadd.click()
        grid_input(driver, item)
    
    
    sleep(2)
    
    btnadd = driver.find_element_by_id("btnadd_material_item")
    for item in material_list:
        btnadd.click()
        grid_input(driver,item)
    
    sleep(2)
    
    driver.find_element_by_id("BatchAddWindow").find_element(by=By.LINK_TEXT ,value="保存").click()
    
    
    #driver.quit()
    

      

  • 相关阅读:
    在排序数组中查找元素
    搜索旋转排序数组
    下一个排列
    括号生成(回溯法)
    PHP之表单
    PHP之超级全局变量
    PHP之数组
    PHP之字符串
    PHP之常量
    PHP之echo/print
  • 原文地址:https://www.cnblogs.com/coolyylu/p/8334632.html
Copyright © 2011-2022 走看看