2017-02-21 66 views
3

當我查了一些元素是可見的我那樣做:如何檢查網絡元素當前不可見,硒,C#

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

,它正在

當我嘗試檢查不可見我做這樣的:

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

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

但在這兩種情況下,它都不起作用。如何檢查元素當前不可見/呈現?

回答

0

您可以使用下面的方法,此方法將檢查元素是否可見,但在此之前它將檢查元素是否可用。

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,印度。

0

我更喜歡Java的人,但我希望下面的代碼片段可以幫助你。在檢查其可見性之前,您需要確保您的元素存在。

public boolean isElementVisible(String path) 
    { 
     try { 
      WebElement ele = driver.findElements(by.xpath("path")).get(0); 
     } 
     catch (NoSuchElementException e1) { 
      //System.out.println("Element Not Visible."); 
      return false; 
      } 
     catch(StaleElementReferenceException e2) { 
      //System.out.println("Element Not Visible."); 
      return false; 
      } 
     catch (InvalidSelectorException e3) { 
      //System.out.println("Element Not Visible."); 
      return false;} 


      return ele.Displayed; 
    } 
相關問題