随笔:python+selenium进行UI自动化循环删除一组元素

#coding = utf-8


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


class Delete(unittest.TestCase):

    def setUp(self):
        # 屏蔽自动化受控提示 && 开发者提示
        self.option = webdriver.ChromeOptions()
        self.option.add_experimental_option("excludeSwitches", ['enable-automation', 'load-extension'])
        # 屏蔽'保存密码'提示框
        self.prefs = {}
        self.prefs["credentials_enable_service"] = False
        self.prefs["profile.password_manager_enabled"] = False
        self.option.add_experimental_option("prefs", self.prefs)
        # 打开谷歌浏览器
        self.driver = webdriver.Chrome(options=self.option)
        # 窗口最大化
        self.driver.maximize_window()
        sleep(5)
        self.driver.get(url1)
        sleep(10)
        self.driver.find_element_by_xpath("//button/span[text()='前往AI生态集市']").click()
        sleep(20)
        self.driver.get(url2)
        sleep(10)
        self.assertEqual("cloudAI自动化", self.driver.find_element_by_xpath("//div[text()='cloudAI自动化']").text)
        sleep(2)


    def testdelete(self):
        ActionChains(self.driver).move_to_element(self.driver.find_element_by_xpath("//div[text()='cloudAI自动化']")).perform()
        sleep(1)
        ActionChains(self.driver).move_to_element(self.driver.find_element_by_xpath("//a/span[text() = '个人中心']")).perform()
        self.driver.find_element_by_xpath("//a/span[text() = '个人中心']").click()
        sleep(5)
        self.driver.find_element_by_xpath("//div[@id='tab-sixth']/span[contains(text(),'下载')]").click()
        sleep(5)
        #获取这组元素生成list
        els = self.driver.find_elements_by_xpath("//div[@id='pane-sixth']//div[contains(text(),'(该资源已删除)')]")
        sleep(5)
        print(els)
        sleep(2)
        print(len(els))
        sleep(10)
        i=0
        #进行循环删除
        while i

 

你可能感兴趣的:(随笔)