Reputation: 429
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:
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?
Upvotes: 0
Views: 8929
Reputation: 2305
Instead of By.name
, you should use By.id
instead. Therefore, use either of these:
By.Id("SearchButton")
By.CssSelector("input#SearchButton")
By.Xpath("//input[@id='SearchButton']")
Note: syntax could be wrong, please adjust depending on your programming language
Upvotes: 0
Reputation: 45
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;
}
}
Upvotes: -1
Reputation: 1939
The input type here is submit (by looking at your HTML code) so I would strongly advise to try the submit() function of Selenium.
Upvotes: 0