Shadow Root and Canvas using OCR | Bondar Academy
Course: AI-based testing with testRigor
Module: Interation with Web Elements
Instructor: Artem Bondar
Lesson Summary
This lesson focuses on the optical character recognition (OCR) feature in test automation, particularly for handling closed shadow DOM elements and canvas images. Key Concepts Closed Shadow DOM : A web design technique that isolates code, making it difficult for automation frameworks to interact with elements inside it. Optical Character Recognition (OCR) : A method used to recognize text within images, which can be essential for interacting with elements that are not directly accessible through standard automation techniques. Demonstration The lesson demonstrates how to use OCR to click a button labeled "open it" that resides within a closed shadow DOM. The initial attempt to click the button using a standard text descriptor fails due to the shadow DOM's restrictions. click open it using OCR, only using the mouse This command allows the test to recognize the button's text as an image and successfully click it. Additional Example Another example involves interacting with a pie chart rendered on a canvas. The values cannot be selected by text directly, but OCR can be used to recognize and validate these values: check that page contains France: 310 using OCR Summary In summary, when dealing with closed shadow DOMs or canvas elements, using OCR is a powerful technique in test automation. Always specify actions with OCR when the text is part of an image or not directly accessible.