1、页面上下滚动,滚动的位置根据Y坐标
js = f"window.scrollTo(0,{val});"
driver.execute_script(js)
2、页面上下滚动,滚动到目标元素处
selector = case.get('selector')
driver = mainhandler.driver
ele = get_element(driver, selector)
try:
#向下滚动
driver.execute_script("arguments[0].scrollIntoView();", ele)
#可能有页眉遮挡,向下移动x个px
driver.execute_script("window.scrollBy(0, -40)")
except:
#向上滚动
driver.execute_script("arguments[0].scrollIntoView(false);", ele)
#可能有页脚遮挡,向上移动x个px
driver.execute_script("window.scrollBy(0, 40)")
3、左右滚动
js = f'document.getElementsByClassName("elx-table--body-wrapper body--wrapper")[0].scrollLeft={val}'
driver.execute_script(js)