0

I am new to Selenium.

My issue is that I'm trying to click an element but Selenium is throwing a timeout exception, even if I increase the timeout value.

Do I need to use xpath instead of id?

The HTML Code is:

enter image description here My code looks like this

 void searchquotation() throws TimeoutException {
    try {
          WebDriverWait wait = new WebDriverWait(driver, 15);
          WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("SearchButton")));
          element.click();
       }
    catch(TimeoutException e) {
         System.out.println("Timeout occured");
       }

Am I doing anything wrong?

armatita
  • 12,825
  • 8
  • 48
  • 49
Manish B
  • 389
  • 1
  • 4
  • 19
  • Please ensure first at browser console using this javascript document.getElementsByName('SearchButton') you are getting this button or not? – Saurabh Gaur May 19 '16 at 12:46

3 Answers3

0

The input type here is submit (by looking at your HTML code) so I would strongly advise to try the submit() function of Selenium.

Anand
  • 1,899
  • 1
  • 13
  • 23
0

Instead of By.name, you should use By.id instead. Therefore, use either of these:

  1. By.Id("SearchButton")
  2. By.CssSelector("input#SearchButton")
  3. By.Xpath("//input[@id='SearchButton']")

Note: syntax could be wrong, please adjust depending on your programming language

Saikat
  • 14,222
  • 20
  • 104
  • 125
kurakura88
  • 2,185
  • 2
  • 12
  • 18
-1
    try below code, even timeout exception occurs, it will try 4 time to click on it. assuming locator is correct By.name("SearchButton")

    public void searchquotation()
    int count=0;
    while(count<4)
    {
     try { 
    WebElement x = driver.findElement(By.name("SearchButton")));
    WebDriverWait element=new WebDriverWait(driver,15);
    element.until (ExpectedConditions.presenceOfElementLocated(By.name("SearchButton"))); 
    x.click(); 
count=count+4;
    } 
    catch(TimeoutException e) { 
    count=count+1;
    System.out.println("Timeout occured");
    continue;
    }
    }