In Selenium, locating strategies are techniques used to identify web elements on a page so that actions (like click, type, etc.) can be performed on them. Selenium provides multiple locators to interact with HTML elements. Below is a complete list of Selenium locators, with details , HTML examples , and code snippets for each. ๐ 1. ID ✅ Best when the element has a unique ID. ๐ง HTML: <input id="username" type="text"> ๐งช Selenium (Java): driver.findElement(By.id("username")).sendKeys("testuser"); ๐ 2. Name ✅ Useful when the element has a unique name attribute. ๐ง HTML: <input name="password" type="password"> ๐งช Selenium: driver.findElement(By.name("password")).sendKeys("mypassword"); ๐ 3. Class Name ⚠️ Use only when class is unique or combined with other locators. ๐ง HTML: <button class="login-button">Login</button> ๐งช Selenium: driver.findEleme...
Comments
Post a Comment