Locating elements in selenium using python

  • Another useful way to find an item is using the selenium find element XPath by python. You use XPath to access the element when a proper I d or name attribute is not present in the code.
  • XPath lets you locate an item using either the Absolute (not the preferred way), or the Relative XPath. Absolute XPaths specifies the root position of an object (html). Using Absolute XPath isn’t an efficient tool, however
  • This is because if you just make a small improvement in the code of the web page. Absolute XPath can shift, and it may not be possible for the webdriver to locate the item with the old.
  • In the case of Relative XPath, you try to locate a nearby element (ideally a parent element) for which an I d or name attribute is given. Now you can measure the target element’s XPath relative to the nearby object. This XPath ‘s chances of changing are very low , making our tests more reliable.
  • And both of these ways enable us to locate an item that has an attribute I d or name.
  • XPath locators may also use other attributes than I d and name to locate an entity.
  • For user SignUp, let’s take the following HTML code to understand the Absolute and Relative direction.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
mahesh reddy

mahesh reddy

Python certification training course will help you master the concepts and gain in-depth experience on writing Python code and packages like SciPy, Matplotlib,