通过name的方式@staticmethod
def isElementPresent():
# 判断页面元素是否存在
operation = ActionModule(method=Vue2ElementMethod.get_element,handle_value="其他出入库详情-按钮栏-反审核",sleep_time=2)
err, res = ea.run_case_for_module(operation)
assert err is None, err
if res:
return True
else:
# 找不到元素时输出none
return False
@pytest.mark.skip(reson="异常类")
@pytest.mark.dependency(depends=["open_page"])
def test_isElementPresent():
elem = otherInStock.isElementPresent()
if elem:
print("所查找的元素存在于页面上")
else:
print("所查找的元素不存在于页面上")
02使用异常类的方式
执行代码
def isElementPre(self,by,value):
# from selenium.common.exceptions import NoSuchElementException下载依赖
try:
element = self.driver.find_element(by = by,value= value)
except NoSuchElementException as e:
print(e)
# 发生了NoSuchElementException异常,说明页面未找到该元素,返回False
return False
else:
# 没有发生异常,表示在页面找到元素
return True
@pytest.mark.skip(reson="异常类")
def test_isElementPresent(self):
# 判断元素id属性值为query的页面元素是否存在
elem = otherInStock.isElementPresent("id","query")
if elem:
print("所查找的元素存在于页面上")
else:
print("所查找的元素不存在于页面上")
判断元素是否可用