![](/img/trans.png)
[英]Python lxml: How to tell if an element has been removed from a tree?
[英]Python: How can I verify that an element on the page has been removed?
我的UI
上有一个“ Clear Filter
按钮,在单击该按钮后将其删除。
我的测试用例如下:
1)单击清除过滤器按钮
2)检查“清除过滤器”按钮是否已从用户界面中删除
在下面的代码中,我单击了按钮,然后尝试再次单击它,因为它不存在,因此测试用例应该通过,但是我试图通过再次尝试单击它来验证失败,但这并不似乎是最好的方法...
log_page.clear_filter_bttnclick()
try:
if log_page.clear_filter_bttnclick():
testrailFunctions.failed()
except NoSuchElementException:
testrailFunctions.passed()
我可以在这里使用try/except
来验证按钮是否已删除,或者是否有更好的方法来确认UI
上不再存在“ Clear Filter
按钮?
干杯
您可以检查元素是否存在。
在python中,它应该执行以下操作:
from selenium.common.exceptions import NoSuchElementException
def check_exists_by_xpath(xpath):
try:
webdriver.find_element_by_xpath(xpath)
except NoSuchElementException:
return False
return True
资源 :-
Python-Selenium WebDriver-检查元素是否存在
要么
方法返回WebElement对象,而不是对象列表。 您必须执行以下操作:
if len(browser.find_elements_by_xpath('//path')) == 0:
print ('element not present')
对不起:-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.