Skip to content
CodeKruPro

Write a function that returns element text

Automation taskEasyPython only

A common review comment: "Do not repeat the find-and-read code in every test." Wrap it in a small function that returns the text. It is the first step towards page objects (classes that keep the locators and actions of one page together), where each page keeps such helpers in one place.

Write a Function That Returns Element Text

Write a Function That Returns Element Text

A function can take an element and return its text. The rest of the script calls that function.

Task:

  1. Write a function that returns element.text
  2. Open Text Fields
  3. Print the h2 text using the function

Print the lines below exactly.

Expected output:

Heading: Text Fields