Bird
0
0

You want to create a Base Page method that waits for an element to be clickable and then clicks it. Which of the following implementations correctly applies this pattern?

hard📝 Application Q8 of 15
Selenium Java - Page Object Model
You want to create a Base Page method that waits for an element to be clickable and then clicks it. Which of the following implementations correctly applies this pattern?
Apublic void clickWhenClickable(By locator) { new WebDriverWait(driver, Duration.ofSeconds(10)) .until(ExpectedConditions.elementToBeClickable(locator)) .click(); }
Bpublic void clickWhenClickable(By locator) { driver.findElement(locator).click(); }
Cpublic void clickWhenClickable(By locator) { WebElement element = driver.findElement(locator); element.click(); }
Dpublic void clickWhenClickable(By locator) { new WebDriverWait(driver, Duration.ofSeconds(10)) .until(ExpectedConditions.visibilityOfElementLocated(locator)); driver.findElement(locator).click(); }
Step-by-Step Solution
Solution:
  1. Step 1: Understand waiting for clickable element

    ExpectedConditions.elementToBeClickable waits for visibility and enabled state.
  2. Step 2: Check method chaining correctness

    public void clickWhenClickable(By locator) { new WebDriverWait(driver, Duration.ofSeconds(10)) .until(ExpectedConditions.elementToBeClickable(locator)) .click(); } waits and then clicks in one chain, which is correct and concise.
  3. Final Answer:

    Method chaining wait and click with elementToBeClickable -> Option A
  4. Quick Check:

    Use elementToBeClickable with wait then click [OK]
Quick Trick: Use elementToBeClickable for safe clicking [OK]
Common Mistakes:
  • Clicking without wait causes flaky tests
  • Waiting only for visibility misses enabled state
  • Separating wait and click without chaining risks stale element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes