自动化分类列表整合xd

2021-04-06  本文已影响0人  Chaweys

category.py

#coding=utf-8

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import unittest

class CatagoryTest(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get("http://xdclass.net")

    def tearDown(self):
        print("用例执行结果")
        pass

    def test_catagory(self):
        driver=self.driver
        #定位首页的"后端&框架"
        menu_element=driver.find_element_by_css_selector("#app > div > div.main > div.banner.w > div.l_course_list > ul > li:nth-child(1)")
        #鼠标移动上去
        ActionChains(driver).move_to_element(menu_element).perform()

        time.sleep(2)

        #鼠标移动之后弹出选项,定位java并点击
        sub_menu_element=driver.find_element_by_css_selector("#app > div > div.main > div.banner.w > div.innerbox > div.base > div.sort > a:nth-child(2)")
        sub_menu_element.click()

        element=driver.find_element_by_css_selector('#app > div > div.contaniner > div > div > div.direction.clearfix > span')
        self.assertEqual(element.text,'方向:',msg='鼠标移动点击失败')
        driver.close()

if __name__ == '__main__':
    unittest.main()
上一篇下一篇

猜你喜欢

热点阅读