2

I'm not a native english speaker, I'm sorry for my English. :)

I'm using Selenium Webdriver + Python. I have a custom scrollbar is on my page.

<div class="k-scrollbar k-scrollbar-vertical" style="width: 18px;"><div style="width:1px;height:1102px"></div></div>


    <div style="width:1px;height:1102px"></div>

EV of this scrollbar has method "Scroll", code is:

function updateGridScrollInState() {
  if (typeof window.GridProfile_Grid === 'object') {
    window.GridProfile.ScrollY = window.GridProfile_Grid.data("kendoGrid").virtualScrollable.verticalScrollbar.scrollTop();
  }
}

I can to manipulate with it, I know scrollbar's locator, but I can not understand how I could scroll to specific element into grid with javascript through driver.execute_script(some_script).

I need to move to element which is located outside of viewport: it is grid, grid has 33 rows, but only 22 rows is displayed, other 11 rows is displayed if I scroll down. I've tried to drag_and_drop this scrollbar:

ActionChains(driver).drag_and_drop(my_custom_scrollbar,  list_of_grid_rows[30]).perform()

but I get Exeption:

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (1015, 1242.699951171875) is out of bounds of viewport width (1920) and height (968)

I guess I can just drag_and_drop while list_of_grid_rows[index] is not displayed. But how can I get this result? Maybe I must to use value of height of scrollbar somehow?

Thank you an advance!

1 Answer 1

2

The python API has an element attribute that causes the desired element to be scrolled into view. I assume it would still work even though there is custom scrolling on the page. The first step is to get the locator of the element you want scrolled into view. It sounds like you have that. Let's call it [element]. Next, if you have verified it exists on the page, then do:

coordinates = [element].location_once_scrolled_into_view

Even thought you may not care about the coordinates, this command will cause the target to be scrolled into view. Selenium Python Element API.

Sign up to request clarification or add additional context in comments.

1 Comment

It is working! Thank you! While I was waiting an answer I found solution too: driver.switch_to.default_content() #switch to grid driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_xpath(xpath).find_elements_by_tag_name('tr')[index]) #after switch_to() I can use scrollIntoView() from JavaScript, it will scroll down my grid already driver.find_element_by_xpath(xpath).find_elements_by_tag_name('tr')[index].click() But your answer is more usable. Thank you again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.