Complete the code to wait for the element to be visible before clicking.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement element = wait.until(ExpectedConditions.[1](By.id("submitBtn"))); element.click();
The method visibilityOfElementLocated waits until the element is visible on the page, which helps avoid timing failures when clicking.
Complete the code to pause the test execution for 5 seconds (not recommended but sometimes used).
try { Thread.[1](5000); } catch (InterruptedException e) { e.printStackTrace(); }
The Thread.sleep method pauses the test execution for the specified milliseconds, helping to avoid timing issues but is not the best practice.
Fix the error in the explicit wait code to wait until the element is clickable.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15)); WebElement button = wait.until(ExpectedConditions.[1](By.id("loginBtn"))); button.click();
The correct method to wait until an element is clickable is elementToBeClickable. This ensures the element can be clicked without timing failures.
Fill both blanks to create a fluent wait that ignores NoSuchElementException and waits 20 seconds polling every 2 seconds.
Wait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds([1]))
.pollingEvery(Duration.ofSeconds([2]))
.ignoring([3].class);The fluent wait is set to timeout after 20 seconds, poll every 2 seconds, and ignore NoSuchElementException to handle timing issues gracefully.
Fill all three blanks to create a custom ExpectedCondition that waits until the page title contains 'Dashboard'.
ExpectedCondition<Boolean> titleContainsDashboard = driver -> driver.getTitle().[1]("[2]") [3];
The lambda checks if the title contains the word Dashboard and uses the ternary operator ? : to return true or false, helping synchronization by waiting for the correct page.