selenium,unittest——下拉菜單操作,百度賬號設置修改
#encoding=utf-8
from selenium import webdriver
import time,unittest, re,sys
from HTMLTestRunner import HTMLTestRunner
from selenium.webdriver.common.action_chains import ActionChains
‘‘‘
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
‘‘‘
if sys.getdefaultencoding() != ‘utf-8‘:
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
class Test(unittest.TestCase):
‘‘‘百度登錄‘‘‘
@classmethod
def setUpClass(self):
self.driver=webdriver.Firefox()
self.driver.get("http://www.baidu.com")
time.sleep(10)
def test_login(self):
mouse = self.driver.find_element_by_link_text(‘設置‘)
ActionChains(self.driver).move_to_element(mouse).perform()
#調用ActionChains的方法時,會將所有的操作按順序存放在一個隊列裏,調用perform()方法時,隊列中的事件會依次執行
self.driver.find_element_by_link_text(‘搜索設置‘).click()
self.driver.find_element_by_link_text(u"保存設置").click()
time.sleep(3)
self.driver.switch_to.alert.accept()
@classmethod
def tearDownClass(self):
self.driver.quit()
if __name__==‘__main__‘:
unittest.main()
selenium,unittest——下拉菜單操作,百度賬號設置修改