ui自动化_操作界面元素

操作界面元素

#!/usr/bin/env python

# -*- coding:utf-8 -*-

from time import sleep

import autoit

from selenium.webdriver import ActionChains

from selenium.webdriver.common import action_chains

from selenium.webdriver.support.select import Select

def test_input(driver):

    name = driver.find_element_by_name("t1")

    # 清空

    name.clear()

    sleep(1)

    # 填值

    name.send_keys("sdfsdf")

def test_radio(driver):

    driver.find_element_by_xpath('//label[@role="radio"]//span[text()="广州"]').click()

def test_select_1(driver):

    # 通过标签名定位下拉框

    sel = driver.find_element_by_tag_name("select")

    # 使用操作下拉框的类实例化

    s = Select(sel)

    # 通过下拉框选项文本选择

    s.select_by_visible_text("小米")

    sleep(1)

    # 通过下拉选项的value值选择

    s.select_by_value("huawei")

    sleep(1)

    # 通过下拉选项的序号选择 从0开始

    s.select_by_index(1)

    sleep(1)

def test_select_2(driver):

    driver.find_element_by_xpath("//select/option[text()='华为']").click()

    sleep(1)

def test_hover(driver):

    sleep(1)

    zhi_nan = driver.find_element_by_xpath('(//span[text()="指南"])[last()]')

    action = ActionChains(driver)

    action.move_to_element(zhi_nan)

    action.perform()

    sleep(1)

def test_splider(driver):

    sleep(1)

    splider = driver.find_element_by_xpath(

        '''//label[text()="普通滑块"]/../div//div[@class="el-tooltip el-slider__button"]''')

    action = ActionChains(driver)

    action.drag_and_drop_by_offset(splider,100,0).perform()

    action.reset_actions()

    sleep(1)

    action.drag_and_drop_by_offset(splider, -100, 0).perform()

def test_date(driver):

    da = driver.find_element_by_xpath('//label[text()="多个日期"]/../div//inp')

    da.send_keys("2020-01-18")

    sleep(1)

def test_update_value(driver):

    sleep(1)

    js = "var xpath = \"" + "//input[@placeholder='选择时间']" + "\";var element = document.evaluate(xpath,document,null,XPathResult.ANY_TYPE,null).iterateNext();element.setAttribute(\"" + "value" + "\",\"" + "20:30" + "\");"

    driver.execute_script(js)

def test_upload_file_1(driver):

    file = driver.find_element_by_xpath('//label[text()="原始上传"]/..//input')

    file.send_keys("C:\\Users\\xue00\\Desktop\\safasdf.html")

def test_upload_file_2(driver):

    driver.find_element_by_xpath('//label[text()="点击上传"]/..//span').click()

    sleep(2)

    # pip install pyautoit-win64

    autoit.control_set_text("打开", "Edit1","C:\\Users\\xue00\\Desktop\\safasdf.html")

    sleep(2)

    autoit.control_click("打开", "Button1")

    sleep(2)

    pass

def test_element(driver):

    yi_ji = driver.find_element_by_xpath('//label[text()="普通树"]/..//span[text()="一级 1"]/../span[1]')

    yi_class = yi_ji.get_attribute("class")

    if "expanded" not in yi_class:

        yi_ji.click()

你可能感兴趣的:(ui自动化_操作界面元素)