selenium自动测试
import requests
import sys
import io
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8') #改变标准输出的默认编码
browser = webdriver.Chrome('C:\chromedriver.exe')
#登录页面
url = r'http://192.168.102.103:8080/mu/'
# 访问登录页面
browser.get(url)
# 等待一定时间,让js脚本加载完毕
browser.implicitly_wait(3)
#输入用户名
username = browser.find_element_by_id('username')
username.send_keys('admin')
#输入密码
password = browser.find_element_by_id('password')
password.send_keys('11111')
#点击“登录”按钮
login_button = browser.find_element_by_xpath('//td/img[1]')
login_button.click()
browser.switch_to.frame(browser.find_element_by_xpath('/html/frameset[1]/frameset[1]/frameset[1]/frameset[1]/frame[2]'))
butten = browser.find_element_by_id('Bar_panel2_c')
butten.click()
butten = browser.find_element_by_xpath('//div[@id="Bar_panel2_b0"]/img[1]')
actions = ActionChains(browser)
actions.click(butten)
actions.perform()
browser.switch_to.default_content();
browser.switch_to.frame(browser.find_element_by_xpath('/html/frameset[1]/frameset[1]/frameset[2]/frameset[1]/frame[2]'))
link = browser.find_element_by_link_text("aaa")
print(link.get_attribute('href'))
#butten = browser.find_element_by_xpath('//table[@id="table0"]/tbody/tr[5]/td[1]/input[1]')
butten = browser.find_element_by_xpath('//input[@value=" 添 加 "]')
butten.click()
select = Select(browser.find_element_by_id('centerId'))
select.select_by_index(1)
editIP = browser.find_element_by_id('serverIp')
editIP.send_keys('127.0.0.1')
editname = browser.find_element_by_id('serverName')
editname.send_keys('name')
editname = browser.find_element_by_id('keepAlivePeriod')
editname.send_keys('59')
editloginname = browser.find_element_by_id('serverLoginName')
editloginname.send_keys('admin')
editlocation = browser.find_element_by_id('installLocation')
editlocation.send_keys('安装位置')
editdesc = browser.find_element_by_id('description')
editdesc.send_keys('设备描述')
#网页截图
browser.save_screenshot('C:/picture1.png')
#打印网页源代码
#print(browser.page_source.encode('utf-8').decode())
browser.implicitly_wait(10)
browser.quit()