Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用SeleniumWebDriver滚动自定义滚动条_Javascript_Python_Selenium - Fatal编程技术网

Javascript 如何使用SeleniumWebDriver滚动自定义滚动条

Javascript 如何使用SeleniumWebDriver滚动自定义滚动条,javascript,python,selenium,Javascript,Python,Selenium,我不是以英语为母语的人,我为我的英语感到抱歉。:) 我正在使用SeleniumWebDriver+Python。我的页面上有一个自定义滚动条 <div class="k-scrollbar k-scrollbar-vertical" style="width: 18px;"><div style="width:1px;height:1102px"></div></div> <div style="width:1px;height:

我不是以英语为母语的人,我为我的英语感到抱歉。:)

我正在使用SeleniumWebDriver+Python。我的页面上有一个自定义滚动条

<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>
我可以使用它进行操作,我知道滚动条的定位器,但我不明白如何通过driver.execute_脚本(一些_脚本)使用javascript将特定元素滚动到网格中

我需要移动到位于视口外部的元素:它是栅格,栅格有33行,但只显示22行,如果向下滚动,则显示其他11行。我已尝试拖放此滚动条:

ActionChains(driver).drag_and_drop(my_custom_scrollbar,  list_of_grid_rows[30]).perform()
但我有一个例外:

selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: (1015, 1242.699951171875) is out of bounds of viewport width (1920) and height (968)
我想我可以在不显示网格行列表[索引]的情况下拖放。但是我怎样才能得到这个结果呢?也许我必须使用滚动条的高度值


谢谢你的预付款

python API有一个元素属性,该属性使所需的元素滚动到视图中。我认为即使页面上有自定义滚动,它仍然可以工作。第一步是获取要滚动到视图中的元素的定位器。听起来你有这个。我们称之为[元素]。接下来,如果您已验证页面上是否存在,请执行以下操作:

coordinates = [element].location_once_scrolled_into_view

即使您可能不关心坐标,此命令也会导致目标滚动到视图中

它正在工作!非常感谢。当我等待答案时,我也找到了解决方案:
driver.switch_to.default_content()#switch to grid
driver.execute(参数[0].scrollIntoView()),driver.find_element_by_xpath(xpath)。find_elements__by_标记_name('tr')[index])#切换到()后,我可以使用JavaScript中的scrollIntoView(),它将向下滚动我的网格已
驱动程序。通过xpath(xpath)查找元素。通过标记名称('tr')[index]查找元素。单击()
,但您的答案更有用。再次感谢你!
coordinates = [element].location_once_scrolled_into_view