Complete the code to locate a button with exact text 'Submit'.
WebElement button = driver.findElement(By.xpath("//button[text()=[1]]"));
In XPath, text() must be compared to a string literal enclosed in single quotes inside the double quotes of Java string.
Complete the XPath to find a link (<a>) element containing the text 'Learn More'.
WebElement link = driver.findElement(By.xpath("//a[contains(text(), [1])]"));
XPath string literals inside Java strings should be enclosed in single quotes for correct syntax.
Fix the error in the XPath to select a div with text exactly 'Welcome'.
WebElement div = driver.findElement(By.xpath("//div[text()=[1]]"));
The XPath text() function requires the text to be enclosed in single quotes inside the Java string.
Fill both blanks to locate a span element containing text 'Error' and having class 'alert'.
WebElement alertSpan = driver.findElement(By.xpath("//span[contains(text(), [1]) and contains(@class, [2])]"));
XPath string literals should be enclosed in single quotes inside the Java string. So use single quotes for both text() and @class values.
Fill all three blanks to find a button with exact text 'Cancel', visible, and with id 'btnCancel'.
WebElement cancelBtn = driver.findElement(By.xpath("//button[text()=[1] and @id=[2] and not(contains(@style, [3]))]"));
Use single quotes inside XPath string literals for text and attribute values. The style check uses 'display:none' to exclude hidden elements.