Complete the code to find an element whose text contains 'Submit'.
WebElement button = driver.findElement(By.xpath("//button[[1](text(), 'Submit')]");
The contains() function checks if the text contains the given substring.
Complete the code to find an element whose id starts with 'user_'.
WebElement input = driver.findElement(By.xpath("//input[[1](@id, 'user_')]");
The starts-with() function checks if the attribute value begins with the given string.
Fix the error in the XPath expression to find a link whose href contains 'login'.
WebElement link = driver.findElement(By.xpath("//a[[1](@href, 'login')]");
The correct function name is starts-with() or contains(). Here, to check if href contains 'login', use contains(). The option 'start-with' is misspelled, 'contain' is invalid.
Fill both blanks to find a div element whose class starts with 'alert' and contains 'error'.
WebElement alertDiv = driver.findElement(By.xpath("//div[[1](@class, 'alert') and [2](@class, 'error')]");
Use starts-with() to check the class starts with 'alert' and contains() to check it contains 'error'.
Fill all three blanks to create a map of elements with keys as uppercase tag names and values as text, filtering only those whose text starts with 'Test'.
Map<String, String> elementsMap = elements.stream() .filter(e -> e.getText().[1]("Test")) .collect(Collectors.toMap(e -> e.getTagName().[2](), e -> e.[3]()));
Use startsWith to filter text starting with 'Test', toUpperCase to convert tag names to uppercase, and getText to get element text.