Skip to content

tracy/Enable middle click in either context #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions modules/page_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from typing import List, Union

from pynput.keyboard import Controller, Key
from pynput.mouse import Button, Controller as MouseController
from pynput.mouse import Button
from pynput.mouse import Controller as MouseController
from pypom import Page
from selenium.common import NoAlertPresentException
from selenium.common.exceptions import (
Expand Down Expand Up @@ -564,7 +565,9 @@ def triple_click(self, reference: Union[str, tuple, WebElement], labels=[]) -> P
"""Actions helper: perform triple-click on a given element"""
return self.multi_click(3, reference, labels)

def control_click(self, reference: Union[str, tuple, WebElement], labels=[]) -> Page:
def control_click(
self, reference: Union[str, tuple, WebElement], labels=[]
) -> Page:
"""Actions helper: perform control-click on given element"""
element = self.fetch(reference, labels)
if self.sys_platform() == "Darwin":
Expand All @@ -574,10 +577,9 @@ def control_click(self, reference: Union[str, tuple, WebElement], labels=[]) ->
self.actions.key_down(mod_key).click(element).key_up(mod_key).perform()
return self

def middle_click(self, reference: Union[str, tuple, WebElement], labels =[]):
"""Perform a middle mouse click on desired element"""
with self.driver.context(self.driver.CONTEXT_CONTENT):
self.driver.maximize_window()
def middle_click(self, reference: Union[str, tuple, WebElement], labels=[]):
"""Actions helper: Perform a middle mouse click on desired element"""
with self.driver.context(self.context_id):
mouse = MouseController()
element = self.fetch(reference, labels)

Expand All @@ -589,14 +591,24 @@ def middle_click(self, reference: Union[str, tuple, WebElement], labels =[]):
outer_height = self.driver.execute_script("return window.outerHeight;")
chrome_height = outer_height - inner_height

element_x = window_position['x'] + element_location['x'] + (element_size['width'] / 2)
element_y = window_position['y'] + element_location['y'] + (element_size['height'] / 2) + chrome_height
element_x = (
window_position["x"]
+ element_location["x"]
+ (element_size["width"] / 2)
)
element_y = (
window_position["y"]
+ element_location["y"]
+ (element_size["height"] / 2)
+ chrome_height
)
mouse.position = (element_x, element_y)

time.sleep(1)
# Need a short wait to ensure the mouse move completes, then middle click
time.sleep(0.5)
mouse.click(Button.middle, 1)
return self

def context_click(
self, reference: Union[str, tuple, WebElement], labels=[]
) -> Page:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from platform import system

import pytest
from selenium.webdriver import Firefox

Expand All @@ -24,6 +26,7 @@ def temp_selectors():
TEST_URL = "https://addons.mozilla.org/en-US/firefox/addon/popup-blocker/"


@pytest.mark.skipif(system().lower().startswith("linux"), reason="Bug 1983280")
def test_webextension_completed_installation_successfully_displayed(
driver: Firefox, temp_selectors
):
Expand Down
3 changes: 2 additions & 1 deletion tests/tabs/test_open_new_bg_tab_via_mouse_and_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_open_new_bg_tab_via_mouse_and_keyboard(driver: Firefox):
"""

test_url = "https://www.iana.org/help/example-domains"
example = ExamplePage(driver).open()
example = ExamplePage(driver)
example.open()

# Middle click link, verify new background tab opens with correct URL
example.middle_click("more-information")
Expand Down
Loading