mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
调整滚动功能,未完成
This commit is contained in:
parent
0a73226c4f
commit
b35e646fe0
@ -19,7 +19,7 @@ from .common.errors import ContextLossError, ElementLossError, AlertExistsError,
|
|||||||
NoRectError, ElementNotFoundError
|
NoRectError, ElementNotFoundError
|
||||||
from .common.locator import get_loc
|
from .common.locator import get_loc
|
||||||
from .common.tools import get_usable_path
|
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
|
from .session_element import make_session_ele
|
||||||
|
|
||||||
|
|
||||||
@ -626,7 +626,7 @@ class ChromiumBase(BasePage):
|
|||||||
h = right_bottom[1] - y
|
h = right_bottom[1] - y
|
||||||
vp = {'x': x, 'y': y, 'width': w, 'height': h, 'scale': 1}
|
vp = {'x': x, 'y': y, 'width': w, 'height': h, 'scale': 1}
|
||||||
png = self.run_cdp_loaded('Page.captureScreenshot', format=pic_type,
|
png = self.run_cdp_loaded('Page.captureScreenshot', format=pic_type,
|
||||||
captureBeyondViewport=True, clip=vp)['data']
|
captureBeyondViewport=False, clip=vp)['data']
|
||||||
else:
|
else:
|
||||||
png = self.run_cdp_loaded('Page.captureScreenshot', format=pic_type)['data']
|
png = self.run_cdp_loaded('Page.captureScreenshot', format=pic_type)['data']
|
||||||
|
|
||||||
@ -938,13 +938,7 @@ class ChromiumPageScroll(ChromiumScroll):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
ele = self._driver.ele(loc_or_ele)
|
ele = self._driver.ele(loc_or_ele)
|
||||||
try:
|
ele.run_js('this.scrollIntoView({behavior: "smooth", block: "center", inline: "center"});')
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class Timeout(object):
|
class Timeout(object):
|
||||||
|
@ -114,11 +114,8 @@ class ChromiumElement(DrissionElement):
|
|||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
"""返回元素宽和高"""
|
"""返回元素宽和高"""
|
||||||
try:
|
model = self.page.run_cdp('DOM.getBoxModel', nodeId=self._node_id)['model']
|
||||||
model = self.page.run_cdp('DOM.getBoxModel', nodeId=self._node_id)['model']
|
return model['height'], model['width']
|
||||||
return model['height'], model['width']
|
|
||||||
except Exception:
|
|
||||||
return 0, 0
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def set(self):
|
def set(self):
|
||||||
@ -459,6 +456,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
while not self.run_js(js) and perf_counter() < end_time:
|
while not self.run_js(js) and perf_counter() < end_time:
|
||||||
sleep(.1)
|
sleep(.1)
|
||||||
|
|
||||||
|
self.page.scroll.to_see(self)
|
||||||
left, top = self.location
|
left, top = self.location
|
||||||
height, width = self.size
|
height, width = self.size
|
||||||
left_top = (left, top)
|
left_top = (left, top)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user