Skip to content

Fixing clicking outside of a viewport issue - #389

Open
aik099 wants to merge 3 commits into
minkphp:masterfrom
aik099:firefox-scroll-into-view-fix
Open

aik099 wants to merge 3 commits into
minkphp:masterfrom
aik099:firefox-scroll-into-view-fix

Conversation

@aik099

@aik099 aik099 commented Mar 2, 2024 •

Copy link
Copy Markdown
Member

Using the moveto WebDriver command the Firefox will trigger an \WebDriver\Exception\MoveTargetOutOfBounds exception when the element is outside of the viewport:

Move target (194, 1001) is out of bounds of viewport dimensions (1550, 970)

The moveto command is used in these driver methods:

  • clickOnElement
    • click (does clickOnElement internally)
    • check (does clickOnElement internally)
    • uncheck (does clickOnElement internally)
    • setValue (checkboxes only; does clickOnElement internally)
  • mouseOver
    • rightClick (does mouseOver internally)
    • doubleClick (does mouseOver internally)

.

The test suite isn't testing mouse-related operations (listed above) outside of the viewport.

P.S.

@codecov

codecov Bot commented Mar 2, 2024 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.08%. Comparing base (31eeac7) to head (dce2e87).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #389      +/-   ##
============================================
- Coverage     89.42%   89.08%   -0.34%     
- Complexity      184      185       +1     
============================================
  Files             1        1              
  Lines           501      504       +3     
============================================
+ Hits            448      449       +1     
- Misses           53       55       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aik099
aik099 requested a review from stof March 16, 2024 19:50
Comment thread src/Selenium2Driver.php Outdated
{
$this->executeJsOnElement(
$element,
"arguments[0].scrollIntoView({ behavior: 'instant', block: 'end', inline: 'nearest' });"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use nearest as well in the block direction ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use the scrollIntoView method myself. I've only copied the whole line from the PHP WebDriver (see https://github.com/php-webdriver/php-webdriver/blob/11923b4ba312fc9d137266ae67438be65d4d500f/lib/Remote/RemoteWebElement.php#L249 ). I trust that they know what's right here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof, my point here is still valid. I think this driver should scroll to an element exactly the same as the underlying facebook web driver does for webdriver-classic-driver driver.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right that something was off. The WebDriver spec's "scroll into view" (used by Element Click) uses exactly block: "end", inline: "nearest", but "only if the element is not already in view". php-webdriver kept the options and dropped that condition, and I copied php-webdriver.

I tried it in a browser with a fixed footer at the bottom of the page. Always scrolling with block: 'end' moves an element that's already visible on a scrolled page down under the footer, so the click hits the footer. With the condition, visible elements don't move, and elements outside the viewport still scroll like end.

block: 'nearest' would fix that case too; it only differs for elements above the viewport (they end up at the top edge instead of the bottom). I went with the spec instead, so the driver keeps scrolling like a WebDriver click does: an element that's fully inside the viewport isn't scrolled, otherwise block: 'end' is used as before. It's still a single script call.

@aik099
aik099 force-pushed the firefox-scroll-into-view-fix branch from b6823ea to a65aa40 Compare October 31, 2024 12:21
@aik099

aik099 commented Oct 31, 2024

Copy link
Copy Markdown
Member Author

Not merging yet, because I think we need to add a missing test in driver-testsuite.

aik099 and others added 3 commits November 18, 2026 20:17
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants