0

After clicking each transaction of Activity and go back in this website https://immutascan.io/address/0x63e153335a166d0494b81e86cd15d3ad2b730545?tab=0. Then scroll bar is moved to top of the page. enter image description here

I tried with WebDriver driver = new ChromeDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("document.location.reload(true)");

from Refresh Page and Keep Scroll Position I also find out about some script from Retain scrollbar position even after reloading using javascript However, it doesn't work. I expect using selenium to retain scrollbar position even after clicking that back button.

banana
  • 33
  • 4

1 Answers1

0

You can try something like this below, the transaction element that you click on the list you should get the x and y coordinates of the element using element location property and after clicking on it and coming back to the same page you can use actions class to scroll to the previous captured coordinates

import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ExpectedConditions
from selenium import webdriver

URL = 'https://immutascan.io/address/0x63e153335a166d0494b81e86cd15d3ad2b730545?tab=0'
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
driver.get(URL)
actions = ActionChains(driver)

# Scroll to first transaction element
transactionToCLick = WebDriverWait(driver, 30).until(
    ExpectedConditions.visibility_of_element_located((By.XPATH, '//a[text()="218123949"]')))
actions.scroll_to_element(transactionToCLick).perform()

# Get the x and y coordinates of transaction element
x = transactionToCLick.location.get('x')
y = transactionToCLick.location.get('y')

transactionToCLick.click()
# wait for new page load and navigate back
time.sleep(5)
driver.back()

# Scroll back to the original previously clicked transaction element location
actions.scroll_by_amount(x, y).perform()
Abhay Chaudhary
  • 1,763
  • 1
  • 8
  • 13