Skip to main content
Improve spelling and code format
Link
Bharat Mane
  • 6.8k
  • 11
  • 41
  • 69

I am using Selenium v3.8.0, also I doingdo the coding in C#.

Now I try to validate if XPath or the webElement exists on the site, though I don't success

Now I try to validate the text Login

then I want to alert it in console:

Here is my atemptattempt:

               if (IsElementPresent(By.XPath("//h3[@translate='TITLE_LOGIN']")))
               {
                   Console.WriteLine("Element exists");         
               }
               else
               {                    
                       Console.WriteLine("Element not displayed");            
               }
 

   private bool IsElementPresent(By by)
   {
       try
       {
           Driver.Instance.FindElement(by);
           return true;
       }
       catch (NoSuchElementException)
       {
           return false;
       }
   }

see picture below: Picture 1

Link to URL: Owasp Juiceshop

I am using Selenium v3.8.0, also I doing the coding in C#.

Now I try to validate if XPath or the webElement exists on the site, though I don't success

Now I try to validate the text Login

then I want to alert it in console:

Here is my atempt:

               if (IsElementPresent(By.XPath("//h3[@translate='TITLE_LOGIN']")))
               {
                   Console.WriteLine("Element exists");         
               }
               else
               {                    
                       Console.WriteLine("Element not displayed");            
               }
 

   private bool IsElementPresent(By by)
   {
       try
       {
           Driver.Instance.FindElement(by);
           return true;
       }
       catch (NoSuchElementException)
       {
           return false;
       }
   }

see picture below: Picture 1

Link to URL: Owasp Juiceshop

I am using Selenium v3.8.0, also I do the coding in C#.

Now I try to validate if XPath or the webElement exists on the site, though I don't success

Now I try to validate the text Login

then I want to alert it in console:

Here is my attempt:

 if (IsElementPresent(By.XPath("//h3[@translate='TITLE_LOGIN']"))) {
       Console.WriteLine("Element exists");         
 }
 else {                    
       Console.WriteLine("Element not displayed");            
 }

 private bool IsElementPresent(By by) {
       try
       {
           Driver.Instance.FindElement(by);
           return true;
       }
       catch (NoSuchElementException)
       {
           return false;
       }
 }

see picture below: Picture 1

Link to URL: Owasp Juiceshop

Source Link
XsiSec
  • 242
  • 1
  • 4
  • 15

Issue with find element

I am using Selenium v3.8.0, also I doing the coding in C#.

Now I try to validate if XPath or the webElement exists on the site, though I don't success

Now I try to validate the text Login

then I want to alert it in console:

Here is my atempt:

               if (IsElementPresent(By.XPath("//h3[@translate='TITLE_LOGIN']")))
               {
                   Console.WriteLine("Element exists");         
               }
               else
               {                    
                       Console.WriteLine("Element not displayed");            
               }


   private bool IsElementPresent(By by)
   {
       try
       {
           Driver.Instance.FindElement(by);
           return true;
       }
       catch (NoSuchElementException)
       {
           return false;
       }
   }

see picture below: Picture 1

Link to URL: Owasp Juiceshop