1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

selenium webdriver and check if element is present?!!

Discussion in 'C, C++, C#' started by sandrine10, Jun 23, 2014.

  1. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Hi everyone,

    Please let me know how can i use this method on my main void (to check if an element is exist) i'm usinf selenium in c#:
    public bool IsTestElementPresent(IWebDriver driver)
    {
    try
    {
    driver.FindElement(By.Id("Test"));
    return true;
    }
    catch (NoSuchElementException)
    {
    return false;
    }
    }

    Thanks in advance?
     
  2. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Anyone...help?!
     
  3. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    I figured that out by myself.
     
  4. Just a tryhard

    Just a tryhard Newbie

    Joined:
    Mar 31, 2016
    Messages:
    1
    Likes Received:
    0
    Since you didn't share... there is an .is_displayed() method in selenium.

    obj = findelement('something')
    obj.is_displayed() < -- will return true or false
     
  5. jamie3000

    jamie3000 Senior Member Premium Member

    Joined:
    Jun 30, 2014
    Messages:
    1,073
    Likes Received:
    470
    Occupation:
    Finance coder looking for semi-retirement
    Location:
    uk
    What are you using it for out of curiosity?