当我检查某些元素是否可见时,我会这样做:
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/