Forum

Forum
Handle sticky eleme...
 
Notifications
Clear all

[Solved] Handle sticky elements

New Member Guest
Joined: 1 year ago
Posts: 1
Topic starter  

I am dealing with multiple sticky elements to take a non-repetitive full-page screenshot. Updating each element one by one is very time consuming. Is there any way to do this automatically?

I am using java and selenium to run TC's .


   
Amrita Kaur
Member Admin
Joined: 3 years ago
Posts: 107
 

Run the following code using JavaScript executor:

var elements = document.querySelectorAll("*");

// Iterate through the elements and check for "position: sticky"
for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    var style = window.getComputedStyle(element);
    var position = style.getPropertyValue("position");
    if (position === "sticky") {
        // If the element has "position: sticky", set "position" to "relative"
        element.style.position = "absolute";
	// element.style.position = "relative";
    }
    if (position === "fixed") {
        // If the element has "position: fixed", set "position" to "relative"
        element.style.position = "absolute";
	// element.style.position = "relative";
    }    
}

 

You can choose on how you want those elements to appear to using relative/absolute positions.

 

This post was modified 1 year ago by admin