调整滚动功能,未完成

This commit is contained in:
g1879 2023-02-19 22:09:03 +08:00
parent 0a73226c4f
commit b35e646fe0
2 changed files with 6 additions and 14 deletions

View File

@ -19,7 +19,7 @@ from .common.errors import ContextLossError, ElementLossError, AlertExistsError,
NoRectError, ElementNotFoundError
from .common.locator import get_loc
from .common.tools import get_usable_path
from .common.web import offset_scroll, cookies_to_tuple
from .common.web import cookies_to_tuple
from .session_element import make_session_ele
@ -626,7 +626,7 @@ class ChromiumBase(BasePage):
h = right_bottom[1] - y
vp = {'x': x, 'y': y, 'width': w, 'height': h, 'scale': 1}
png = self.run_cdp_loaded('Page.captureScreenshot', format=pic_type,
captureBeyondViewport=True, clip=vp)['data']
captureBeyondViewport=False, clip=vp)['data']
else:
png = self.run_cdp_loaded('Page.captureScreenshot', format=pic_type)['data']
@ -938,13 +938,7 @@ class ChromiumPageScroll(ChromiumScroll):
:return: None
"""
ele = self._driver.ele(loc_or_ele)
try:
self._driver.run_cdp('DOM.scrollIntoViewIfNeeded', nodeId=ele.ids.node_id)
except Exception:
ele.run_js("this.scrollIntoView();")
if not ele.states.is_in_viewport:
offset_scroll(ele, 0, 0)
ele.run_js('this.scrollIntoView({behavior: "smooth", block: "center", inline: "center"});')
class Timeout(object):

View File

@ -114,11 +114,8 @@ class ChromiumElement(DrissionElement):
@property
def size(self):
"""返回元素宽和高"""
try:
model = self.page.run_cdp('DOM.getBoxModel', nodeId=self._node_id)['model']
return model['height'], model['width']
except Exception:
return 0, 0
@property
def set(self):
@ -459,6 +456,7 @@ class ChromiumElement(DrissionElement):
while not self.run_js(js) and perf_counter() < end_time:
sleep(.1)
self.page.scroll.to_see(self)
left, top = self.location
height, width = self.size
left_top = (left, top)