While web scraping using Selenium WebDriver with Chrome, I stumbled upon a page containing fixed regions that do not scroll and remain in place relative to the window. Often when trying to scroll to a specific control using Actions.MoveToElement(), the element ends up hidden behind one of these fixed regions. As a result, clicking on the obscured element triggers the fixed region instead, preventing my intended control from being clicked.
The fixed regions are identified by their class attribute class=SomeFixedPositionStyle
. To overcome this issue, I am considering having Selenium inject Javascript code to iterate through each style on the page and change any instances of position:fixed
to position:static
. How can this be implemented?
I have decided against modifying the class attribute of the fixed elements as scrolling resets the class attribute to its original value, including the fixed positioning style.
For instance, you can observe this behavior on a page like where fixed bands appear at the top and bottom while scrolling.
When attempting to scroll to element //*[@id="holdingsTabs"]/ul/li[3]
(the "All" link in the "Holdings" section), it gets positioned beneath the lower fixed region, making it inaccessible for clicking.