c# - 如何检查 web 元素当前不可见,selenium,c#

标签 c# selenium

当我检查某些元素是否可见时,我会这样做:

public void CheckingVisible {
 Assert.IsTrue(WebElement.Displayed); 
} 

它正在运行

当我尝试检查不可见时,我会这样做:

public void CheckingNotVisible { Assert.IsFalse(WebElement.Displayed); } 

还有

public void CheckingNotVisible { Assert.IsTrue(!WebElement.Displayed); }

但在这两种情况下都不起作用。如何检查该元素当前是否可见/未呈现?

最佳答案

你可以使用下面的方法,这个方法会检查元素是否可见,但在此之前它会检查元素是否可用。

public void CheckVisible() throws Exception
{
    boolean eleche,eleche1 = false;
        try
        {
            eleche = driver.findElements(by.xpath("path")).size()!=0;
        }catch(InvalidSelectorException ISExcep)
        {
            System.out.println("Element Not Available in Page.");
        }
        if(eleche == true)
        {
        try{
                eleche1=driver.findElement(By.xpath("Path")).isDisplayed();
            }catch(org.openqa.selenium.NoSuchElementException NSEE)
            {
                System.out.println("Element Not Visible.");
            }
            if(eleche1 == true)
            {
                System.out.println("\nElement is Visible.");
            }
        }
}

希望我的回答对您有所帮助。
谢谢你,
Ed D,印度。

关于c# - 如何检查 web 元素当前不可见,selenium,c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42362585/

相关文章:

c# - 如何将数据行流式传输到sql server?

c# - Windows 服务中的 Console.WriteLine()?

c# - 等待输入只读属性消失

java - 如何在 IE 的下拉列表中验证所选选项

c# - 如何使用图形方法传递参数?示例如下

c# - 自定义 XML 序列化 - 包括类名

selenium - 如何处理 IE selenium 上的新选项卡?

ruby-on-rails - 如何在 Ruby 中使用 Selenium webdriver 截取警报的屏幕截图?

java - Selenium 错误: org. openqa.selenium.NoSuchElementException:无法找到元素:{"method":"name","selector":"db_vaults__button"}

c# - 将 IronPython 代码编译为 EXE 或 DLL