name attribute contains the substring user?The selector input[name*='user'] matches all <input> elements whose name attribute contains the substring 'user' anywhere.
Other options mean:
^=starts with$=ends with~=contains a whole word separated by spaces
WebElement element = driver.findElement(By.cssSelector("li:first-child")); // Which assertion below is correct?
The selector li:first-child selects the first <li> child element. To verify its text, use assertEquals comparing expected and actual text.
elements.size()?<ul> <li data-role="admin">Admin</li> <li data-role="user">User1</li> <li data-role="user">User2</li> <li>Guest</li> </ul> List<WebElement> elements = driver.findElements(By.cssSelector("li[data-role='user']")); System.out.println(elements.size());
The selector li[data-role='user'] matches <li> elements with attribute data-role exactly equal to 'user'. There are two such elements.
The :contains() pseudo-class is not a valid CSS selector and is not supported by Selenium's CSS selector engine. It will cause an error.
Other selectors are valid CSS selectors.
data-action='save' and that is the last child of its parent, using CSS selectors and explicit waits?Option B waits for the button with attribute data-action='save' that is the last child and is clickable (visible and enabled). This is best for clicking.
Option B waits only for visibility, which may not guarantee clickability.
Option B waits only for presence in DOM, not visibility.
Option B uses :first-child which is incorrect for last child.