Selenium Locator
Selenium Locator
Website - https://www.saucedemo.com/
Let's break it down in a simpler way so you can easily understand CSS Selectors and XPath.
Used to find elements based on their CSS properties (class, ID, attributes, etc.).
Faster than XPath and simpler to use.
Follows the same syntax used in CSS stylesheets.
How to Write a CSS Selector
Example in HTML
<input type="text" id="user-name" class="input-field">
<button class="submit-button">Login</button>
How to Use in Selenium
driver.find_element(By.XPATH, "//input[@id='user-name']").send_keys("standard_user")
driver.find_element(By.XPATH, "//button[text()='Login']").click()