Complete the code to locate an element by CSS selector.
WebElement button = driver.findElement(By.[1]("button.submit"));
The cssSelector method is used to locate elements using CSS selectors, which is efficient and fast for simple selectors.
Complete the code to locate an element by XPath.
WebElement link = driver.findElement(By.[1]("//a[@href='home.html']"));
The xpath method is used to locate elements using XPath expressions, which are powerful for complex queries.
Fix the error in the locator strategy to find an element by class name.
WebElement input = driver.findElement(By.[1]("form-input"));
The className method locates elements by their class attribute. Using it correctly avoids errors when targeting classes.
Fill both blanks to create a CSS selector that finds all div elements with class 'active' and attribute 'data-id' equal to '123'.
List<WebElement> elements = driver.findElements(By.[1]("div[2][data-id='123']"));
Use cssSelector to locate elements by CSS. The dot . is used to specify a class in CSS selectors.
Fill all three blanks to write an XPath expression that finds a button element with text 'Submit' and attribute 'type' equal to 'button'.
WebElement submitBtn = driver.findElement(By.[1]("//[2][[3]='Submit' and @type='button']"));
Use xpath method with an XPath expression. The tag is button and text() function matches the visible text.