*** Settings *** Library SeleniumLibrary Library SeleniumScreenshots Suite teardown Close all browsers *** Test Cases *** Capture search button Open browser https://www.google.com/?hl=en browser=headlessfirefox Page should contain element css=input[value="Google Search"] ${screenshot}= Capture and crop page screenshot ... ${CURDIR}/button.png ... jquery:[value="Google Search"]:visible %%python module VisionLibrary from robot.libraries.BuiltIn import BuiltIn import cv2 import tempfile class VisionLibrary: def page_should_contain_template(self, filename, similarity=0.8): similarity = float(similarity) sl = BuiltIn().get_library_instance('SeleniumLibrary') with tempfile.TemporaryDirectory() as path: sl.driver.save_screenshot(path + '/image.png') image = cv2.imread(path + '/image.png') template = cv2.imread(filename) result = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) assert max_val >= similarity, \ 'Template not found ({} < {})'.format(max_val, similarity) return (int(max_loc[0] + template.shape[1] / 2), int(max_loc[1] + template.shape[0] / 2)) def click_template(self, filename, similarity=0.8): x, y = self.page_should_contain_template(filename, similarity) sl = BuiltIn().get_library_instance('SeleniumLibrary') el = sl.driver.execute_script( 'return document.elementFromPoint({}, {});'.format(x, y)) el.click() *** Settings *** Library VisionLibrary *** Test Cases *** Click search button Open browser https://www.google.com/?hl=en browser=headlessfirefox Set window size 1200 900 Page should contain template ${CURDIR}/button.png Input text name=q Robot Framework Set focus to element css=body Click template ${CURDIR}/button.png Page should contain robotframework.org Capture page screenshot