繁体   English   中英

Python:如何验证页面上的元素已被删除?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM