Skip to content

How to create locator

Roman Pobotin edited this page Jun 8, 2018 · 4 revisions

For finding locator better use Chrome browser

Steps:

Work in the browser

  • Go to web pages from where you want to get a locator (Google )
  • Find needed locator (search field for example) and right click on it and click "Inspect element"

inspectElement.png

  • Selected locator will be found automatically in DOM

findElement.png

  • Right-click on locator in DOM and click Copy -> Copy XPath

copyXpath.png

You can copy any type of locator, but XPath is easier to read

Work in PyCharm

  • Go to project in PyCharm (project -> framework -> locators.py)
  • Create new class for your new page (or currently created page) class GoogleSearchLocators:
  • Create new variable in class with copied XPath from site search_field = (By.XPATH,"//*[@id='lst-ib']") , where search_field is a name of your variable; By.XPATH type of locator to search; "//*[@id='lst-ib']" copied locator path from site.

createdLocator.png

SUCCESS!

You have been created you first locator in this framework.

Go to the How to create test method page to understand how to use your locators.