mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
update DrissionPage/_elements/chromium_element.py.
新增强制保持元素状态 Signed-off-by: Wen-Ming21 <3348431908@qq.com>
This commit is contained in:
parent
cde7fc7b8d
commit
1bb32ba617
@ -593,7 +593,27 @@ class ChromiumElement(DrissionElement):
|
||||
self._run_js('this.focus();')
|
||||
return self
|
||||
|
||||
def hover(self, offset_x=None, offset_y=None):
|
||||
def keep_pseudo_state(self, forcedPseudoClasses):
|
||||
while self.__dict__.get('keep_count', 0):
|
||||
self.owner.run_cdp('CSS.enable')
|
||||
self.owner.run_cdp('CSS.forcePseudoState', nodeId=self._node_id, forcedPseudoClasses=forcedPseudoClasses)
|
||||
|
||||
def force_pseudo_state(self, keep_state=True, forcedPseudoClasses=None):
|
||||
if not forcedPseudoClasses:
|
||||
forcedPseudoClasses = ['hover']
|
||||
if keep_state and self.__dict__.get('keep_count', 0) == 0:
|
||||
from random import randint
|
||||
x, y = self.owner.rect.size
|
||||
x, y = (x, y) if x <= y else (y, x)
|
||||
self.owner.actions.move_to(self, offset_x=randint(x, y), offset_y=randint(x, y), duration=.1)
|
||||
self.__dict__['keep_count'] = 1
|
||||
Thread(target=self.keep_pseudo_state, args=(forcedPseudoClasses,)).start()
|
||||
if self.__dict__.get('keep_count', 0) > 0 and not keep_state:
|
||||
del self.__dict__['keep_count']
|
||||
return self
|
||||
|
||||
def hover(self, offset_x=None, offset_y=None, keep_hover=False):
|
||||
self.force_pseudo_state(keep_hover, forcedPseudoClasses=['hover'])
|
||||
self.owner.actions.move_to(self, offset_x=offset_x, offset_y=offset_y, duration=.1)
|
||||
return self
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user