Locators Webdriver When Do You Use? When You Cannot Use?
Locators Webdriver When Do You Use? When You Cannot Use?
Locators:
Note: These are all methods of 'By' class in selenium and through findElement method (of
RemoteWebDriver class) or findElements, it will be called.
Referece: Go to https://seleniumhq.github.io/selenium/docs/api/java/ link to see all Java
Selenium classes and associated constructors and methods
ID is the Preferred locator than X-Path because ID is Unique and is faster when compared
to X-Path (slower since it traverses through the DOM). When you find an web element using ID,
it would be easy to target the element successfully. Even though the DOM changes in the future,
ID remains same, whereas xpath may become invalid.
Note: If the ID contains numbers, it is not preferable to use ID since those numbers keeps
changing randomly.