MoveTargetOutOfBoundsException problem with chromedriver version >74

后端 未结 2 1041
清酒与你
清酒与你 2020-12-12 03:07

I don\'t know why ActionChains move_to_element() is not working with chromedriver >74.

(But it works on chromedriver 74 and geckodriver.)

2条回答
  •  孤城傲影
    2020-12-12 03:48

    move_to_element uses internally move_to

    def move_to_element(self, to_element):
        if self._driver.w3c: # default in chromedriver 79
            self.w3c_actions.pointer_action.move_to(to_element)
    
    def move_to(self, element, x=None, y=None):
        #...
        el_rect = element.rect
        left_offset = el_rect['width'] / 2
        top_offset = el_rect['height'] / 2
        left = -left_offset + (x or 0)
        top = -top_offset + (y or 0)
    
        self.source.create_pointer_move(origin=element, x=int(left), y=int(top))
    

    The mouse pointer is moved by offset based on the element position. You are locating the element and then scroll it into view using JavaScript, so the offset is calculated by the wrong coordinates.

    Removing the JavaScript scroll should solve the problem.

提交回复
热议问题