Advertisement

Selenium自动化测试框架中元素存在性判断

阅读量:

#判断特定元素是否存在,可通过调用driver.find_element(by=by, value=value)方法实现,若系统无法定位到该元素,则会触发异常报错

复制代码
    import unittest
    import time
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    
    class VisitSogouByIE(unittest.TestCase):
    def setUp(self):
        # 启动IE浏览器
        self.driver = webdriver.Ie(executable_path="g:\ IEDriverServer")
    
    def isElementPresent(self, by, value):
        # 从selenium.common.exceptions模块导入NoSuchElementException异常类
        from selenium.common.exceptions import NoSuchElementException
        try:
            element = self.dri

全部评论 (0)

还没有任何评论哟~