#-*- coding:utf-8 -*-
# __author__ = 'a1'
import os
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
def setUp():
chromedriver = "D:/Python/Python36-32/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://192.168.2.12")
test_login(driver)
def test_login(driver):
username = "13500010001"
password = "12345678"
driver.find_element_by_id("Login_Name_Input").clear()
driver.find_element_by_id("Login_Name_Input").send_keys(username)
#密码的定位
driver.find_element_by_id("Login_Password_Input").clear()
driver.find_element_by_id("Login_Password_Input").send_keys(password)
# 点击登录
driver.find_element_by_id("Login_Login_Btn").click()
time.sleep(3)
driver.find_element_by_id("BaseFramework_Menu_Strategy").click()
time.sleep(1)
driver.find_element_by_id("StrategyList_Btn_NewClick").click()
time.sleep(3)
driver.find_element_by_id("StrategyNewInfo_Input_Name").send_keys("myStrategy")
time.sleep(2)
#找到元素对象
elSlider = driver.find_element_by_xpath("//form[@class='el-form demo-ruleForm el-form--label-left']//div[@class='el-form-item weight-pack']/div/div/div/div")
#移动到源元素就保持按鼠标左键
ActionChains(driver).move_to_element_with_offset(elSlider,elSlider.size['width'],6).click_and_hold().perform()
time.sleep(1)
#移动到目标位置,x,y坐标,根据像素设置。本例只用到x可以最大设置到380像素为100%。
ActionChains(driver).move_by_offset(35.2,6).perform()
time.sleep(1)
#松开鼠标
ActionChains(driver).release().perform()
time.sleep(3)
driver.close()
setUp()