selenium webdriver and check if element is present?!!

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

  1. sandrine10

    sandrine10 Jr. VIP Jr. VIP

    Joined:
    Apr 14, 2010
    Messages:
    765
    Likes Received:
    84
    Gender:
    Female
    Location:
    WakWak
    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 Jr. VIP Jr. VIP

    Joined:
    Apr 14, 2010
    Messages:
    765
    Likes Received:
    84
    Gender:
    Female
    Location:
    WakWak
  3. sandrine10

    sandrine10 Jr. VIP Jr. VIP

    Joined:
    Apr 14, 2010
    Messages:
    765
    Likes Received:
    84
    Gender:
    Female
    Location:
    WakWak
  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 Elite Member Premium Member

    Joined:
    Jun 30, 2014
    Messages:
    2,021
    Likes Received:
    931
    Occupation:
    Owner of BigGuestPosting.com
    Location:
    uk
    Home Page:
    What are you using it for out of curiosity?