0

I am writing a method in Java using Selenium WebDriver methods, to test if an element is present or not in a webpage.

Below is my piece of code:

public boolean waitForElementPresent(String target) {

     if(target!=null) { 

         driver.manage().timeouts()
            .implicitlyWait(15, TimeUnit.SECONDS);
       try {
          if (driver.findElement(By.name(target))!=null) { log.info("Entered name Condition"); return true; }
        } catch(Exception e) { log.debug(e); return false; }
    } else {
                 log.info("The target is null");
         return false;
     }
 }    

Here the target being sent is "name=go", this target is captured by using selenium IDE. Even though the page is completely loaded and is displaying this particular element, my method is failing with the message 'ERROR: Could not find the Element in the specified time'.

Sree
  • 15
  • 1
  • 3
  • Possible duplicate of [Selenium WebDriver - Test if element is present](https://stackoverflow.com/questions/7991522/selenium-webdriver-test-if-element-is-present) – Apoorva Soni Oct 13 '17 at 07:16

1 Answers1

1

You should pass "go" only in the target.

In your case "go" is the name of the element. Selenium will search in the page with property name like this By.name("go")

So just replace,

findElement(By.name("name=go"))

with

findElement(By.name("go"))
Sravan
  • 591
  • 1
  • 4
  • 16
  • Hi..Thanks for the reply..Its working if i pass By.name("go". – Sree Dec 13 '13 at 06:23
  • @user3098110 if Sravan's answer solved your problem, you should think about accepting this answer by clicking the greyed out 'tick' next to the answer. That will reward Sravan for his answer and show future visitors that this answer is considered your solution. see http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work for more info. –  Dec 14 '13 at 17:10