Skip to content

Conversation

@drobota
Copy link
Contributor

@drobota drobota commented Mar 9, 2018

No description provided.

"""Scrolls an element from given ``locator`` into view.
"""
element = self.find_element(locator)
self.driver.execute_script("arguments[0].scrollIntoView()", element)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that some users are actually using the library on places where JavaScript is not available. Therefore it should be better use Selenium ActionChains. Example like this: ActionChains(self.driver).(element).perform()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only hovers element. I tested in Firefox and it does not scroll.

Copy link
Contributor

Choose a reason for hiding this comment

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

It works with Chrome and Edge. Also there is an exception raised when trying with Firefox.

Traceback (most recent call last): File "test.py", line 16, in <module> ActionChains(driver).move_to_element(element).perform() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py", line 80, in perform self.w3c_actions.perform() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/actions/action_builder.py", line 76, in perform self.driver.execute(Command.W3C_ACTIONS, enc) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (183.5, 5330.85009765625) is out of bounds of viewport width (1280) and height (779) 

I did raise an issue to the Selenium issue tracker: SeleniumHQ/selenium#5601. For mean time, make: if browser is Firefox then use JavaScript, else use ActionChains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it scroll element on my test scroll page?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't try your test page, but this did work with Chrome and Edge: https://gist.github.com/aaltat/a7f71e960d1bc3c6f90bfebb216162f0

Copy link
Contributor Author

@drobota drobota Mar 12, 2018

Choose a reason for hiding this comment

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

I tested it in Chrome and action chain solution works. I will update pr


@keyword
def scroll_element_into_view(self, locator):
"""Scrolls an element from given ``locator`` into view.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change doc string to:

"""Scrolls an element identified by ``locator`` into view. See the `Locating elements` section for details about the locator syntax. New in SeleniumLibrary 3.2.0 """ 
@drobota drobota force-pushed the feature/ISSUE-763 branch from d564a25 to 49a3f0e Compare March 12, 2018 16:53
@drobota drobota force-pushed the feature/ISSUE-763 branch from 49a3f0e to 9117634 Compare March 19, 2018 22:49
@aaltat
Copy link
Contributor

aaltat commented Mar 22, 2018

It looks like test with appveyor did fail for some reason. I hate FF too. I did restart the build and lets see how it goes. Code and tests look OK.

@aaltat
Copy link
Contributor

aaltat commented Mar 22, 2018

Firefox is behaving badly and it has come impossible to get it stable. I did disable the FF build with appveyor.

@rubygeek
Copy link
Contributor

rubygeek commented May 8, 2018

This didn't get added to the changes list .... @drobota would you like credit for adding this to RF? I can update the changes file https://github.com/robotframework/SeleniumLibrary/blob/master/CHANGES.rst if you would like .. or you can submit a new PR

@jimpriest
Copy link

I don't see this in the keywords list either?

@aaltat
Copy link
Contributor

aaltat commented Jul 19, 2018

This feature is in the master code line, but it's unreleased. Therefore the keyword documentation is not updated.

@rubygeek
Copy link
Contributor

rubygeek commented Jul 19, 2018 via email

@aaltat aaltat deleted the feature/ISSUE-763 branch November 30, 2018 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants