我希望能够自动化我的Web浏览器,来旋转一个使用Mapbox创建的地图,然而这只能通过按住右键并围绕着地图移动来完成。
我知道左键有一个点击并保持选项,但是右键有类似的选项吗?目前,我只能使用上下文菜单进行单击右键。
我希望能够自动化我的Web浏览器,来旋转一个使用Mapbox创建的地图,然而这只能通过按住右键并围绕着地图移动来完成。
我知道左键有一个点击并保持选项,但是右键有类似的选项吗?目前,我只能使用上下文菜单进行单击右键。
class PointerActions(Interaction):
def move_to_location(self, x, y):
...
def click(self, element=None):
...
def context_click(self, element=None):
...
# --- Add this function
def context_click_and_hold(self, element=None):
if element:
self.move_to(element)
self.pointer_down(MouseButton.RIGHT)
return self
# ---
def click_and_hold(self, element=None):
...
def release(self):
...
def double_click(self, element=None):
...
文件2:在 Lib/site-packages/selenium/webdriver/common/action_chains.py 中找到并编辑此文件。
将此函数添加到“ActionChains”类中:
class ActionChains(object):
def __init__(self, driver, duration=250):
...
def click(self, on_element=None):
...
# --- Add this function
def context_click_and_hold(self, on_element=None):
if on_element:
self.move_to_element(on_element)
self.w3c_actions.pointer_action.context_click_and_hold()
self.w3c_actions.key_action.pause()
return self
# ---
def click_and_hold(self, on_element=None):
...
def context_click(self, on_element=None):
...
如果 .release() 函数无法在按住右键后释放右键,您应该通过进行以下更改向 .release() 函数添加一个参数:
class PointerActions(Interaction):
def click_and_hold(self):
...
def release(self, button="left"):
button = MouseButton.LEFT if button == "left" else MouseButton.RIGHT
self.pointer_up(button)
return self
def double_click(self):
...
class ActionChains(object):
def pause(self):
...
def release(self, button="left", on_element=None):
"""
Releasing a held mouse button on an element.
:Args:
- on_element: The element to mouse up.
If None, releases on current mouse position.
"""
if on_element:
self.move_to_element(on_element)
self.w3c_actions.pointer_action.release(button)
self.w3c_actions.key_action.pause()
return self
def send_keys(self):
...
TouchActions
,例如touchAc = TouchActions(driver)
touchAc.tap_and_hold(100, 700).scroll(100, 800).perform()
。 - Dilip Meghwal