[PYTHON] Flash Selenium support

Purpose

problem

solution

procedure

  1. Get a screen shot of the screen with Selenium.
  2. Obtain the target coordinate position (x, y) from the Reference image prepared in advance using Template Matcing using OpenCV.
  3. Specify the standard HTML Element (this time the company logo)
  4. Compare the distance from the specified HTML Element to the target coordinate position, determine the offset value, and execute using the previous Method.

kancolle03.png

Implementation

click.py


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

class Browser(object):
    ...

    def click(self, element, x, y):
        """
            element : Target HTML Element
            x : offset_x
            y : offset_y
        """
        self.driver = webdriver.Firefox()
        target = self.driver.find_element_by_id(element)
        off_x = int(target.size["width"]) / 2
        off_y = int(target.size["height"]) / 2
        actions = ActionChains(self.driver)
        actions.move_to_element(target)
        actions.move_by_offset(x - off_x, y - off_y)
        actions.click()
        actions.move_to_element(target)
        actions.perform()

    ...

Conclusion

Recommended Posts

Flash Selenium support
selenium