Explicit and implicit wait

Hi

I am new to selenium (but experienced java developer).

I am using something like below:
pWait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//a[contains(.,’Search&Baskets’)]”)));
pDriver.findElement(By.xpath(“//a[contains(.,’Search&Baskets’)]”)).click();

where pWait is:
WebDriverWait wait = new WebDriverWait(driver, 15);

however when I run the test case I get below error:
Unable to locate element: {“method”:”xpath”,”selector”:”//a[contains(.,’Search&Baskets’)]”}
Command duration or timeout: 4 milliseconds

I thought it should have wait atleast 15 seconds before throwing this exception. From the log above it looks like it threw exception only in 4ms.
and i could see on console that as soon as it hit that line, it threw exception.

I have implicit waiting set as 0 and using explicit wait.

Am i missing anything here.

Also, in explicit and implicit wait, is it upto that much time OR exact that much time,
example if I set implicit wait as 10 sec, then does it mean wait for exact 10 sec OR wait upto 10 sec (if element found then proceed, even if element founf on 6th second)

is above same for explicit wait as well?

Please help

Add Comment
  • 1 Answer(s)

    WebElement element = null;

    WebDriverWait wait = new WebDriverWait(driver, 15); //please check driver object

    element=Wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//a[contains(.,’Search&Baskets’)]”)));

    element.click();

    Default Answered 4 days ago.

    do you see any difference in what i have mentioned above and what you have suggested.

    4 days ago.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.