Extracting Page Values | Bondar Academy
Course: Cypress UI Testing with JavaScript
Module: Interaction with Web Elements
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to extract text values from a web page using Cypress. This is useful for saving values for later use or extracting values from input fields and HTML attributes. Key Examples Covered Example 1: Extracting Label Text Use sci.get to locate the email label. Utilize the then function to get the element instance. Call text method to extract the label value. Print the value to the console using console.log . Example 2: Using Invoke Command Use invoke with the text method to directly get the label value. Print the extracted value to the console. Example 3: Invoking Attribute Values Use invoke with attr to get HTML attributes like class or placeholder . Print the attribute values to the console. Example 4: Invoking Input Field Value Type a value into an input field and use invoke with prop to get the value property. Print the input value to the console. Important Notes If you only need to validate a value, use Cypress assertions directly without invoking the text first. Assertions can be made using methods like shouldContain or have.attribute . This lesson demonstrates how to effectively extract and validate text and attribute values using Cypress, enhancing your testing capabilities.