Complete the code to locate a button by its ID using Selenium in Java.
WebElement button = driver.findElement(By.[1]("submitBtn"));
Using By.id locates the element by its unique ID, which is the most reliable way to find elements.
Complete the code to wait until the element located by CSS selector is visible.
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.[1](".login-form")));
By.cssSelector is used to locate elements using CSS selectors, which can be very precise and reliable.
Fix the error in the locator to find an element by XPath.
WebElement element = driver.findElement(By.[1]("//div[@class='content']"));
By.xpath is the correct method to locate elements using XPath expressions.
Fill both blanks to create a stable locator that finds a button by its text using XPath.
WebElement button = driver.findElement(By.[1]("//button[[2]()='Submit']"));
Using By.xpath with text() allows locating a button by its visible text, which is reliable if the text is unique.
Fill all three blanks to create a dictionary comprehension that maps element IDs to their text if the text length is greater than 3.
Map<String, String> elementsText = elements.stream() .filter(e -> e.getText().length() [1] 3) .collect(Collectors.toMap(e -> e.getAttribute([2]), e -> e.[3]()));
The filter uses > to select elements with text length greater than 3. The attribute "id" gets the element's ID. The method getText() retrieves the element's visible text.