1
1
import copy
2
2
from typing import Literal
3
3
4
+ from pydoll .commands .runtime import RuntimeCommands
4
5
from pydoll .constants import By
5
6
6
7
@@ -26,14 +27,9 @@ class DomCommands:
26
27
'method' : 'DOM.querySelectorAll' ,
27
28
'params' : {},
28
29
}
29
- EVALUATE_TEMPLATE = {'method' : 'Runtime.evaluate' , 'params' : {}}
30
30
BOX_MODEL_TEMPLATE = {'method' : 'DOM.getBoxModel' , 'params' : {}}
31
31
RESOLVE_NODE_TEMPLATE = {'method' : 'DOM.resolveNode' , 'params' : {}}
32
32
REQUEST_NODE_TEMPLATE = {'method' : 'DOM.requestNode' , 'params' : {}}
33
- CALL_FUNCTION_ON_TEMPLATE = {
34
- 'method' : 'Runtime.callFunctionOn' ,
35
- 'params' : {},
36
- }
37
33
GET_OUTER_HTML = {
38
34
'method' : 'DOM.getOuterHTML' ,
39
35
'params' : {},
@@ -42,17 +38,6 @@ class DomCommands:
42
38
'method' : 'DOM.scrollIntoViewIfNeeded' ,
43
39
'params' : {},
44
40
}
45
- GET_PROPERTIES = {
46
- 'method' : 'Runtime.getProperties' ,
47
- 'params' : {},
48
- }
49
-
50
- @classmethod
51
- def get_properties (cls , object_id : str ) -> dict :
52
- """Generates the command to get the properties of a specific object."""
53
- command = cls ._create_command (cls .GET_PROPERTIES , object_id = object_id )
54
- command ['params' ]['ownProperties' ] = True
55
- return command
56
41
57
42
@classmethod
58
43
def scroll_into_view (
@@ -65,20 +50,6 @@ def scroll_into_view(
65
50
object_id = object_id ,
66
51
)
67
52
68
- @classmethod
69
- def call_function_on (
70
- cls ,
71
- object_id : str ,
72
- function_declaration : str ,
73
- return_by_value : bool = False ,
74
- ) -> dict :
75
- """Generates the command to call a function on a specific object."""
76
- command = cls ._create_command (cls .CALL_FUNCTION_ON_TEMPLATE )
77
- command ['params' ]['objectId' ] = object_id
78
- command ['params' ]['functionDeclaration' ] = function_declaration
79
- command ['params' ]['returnByValue' ] = return_by_value
80
- return command
81
-
82
53
@classmethod
83
54
def get_outer_html (cls , node_id : int ) -> dict :
84
55
"""Generates the command to get the outer HTML"""
@@ -123,7 +94,7 @@ def enable_dom_events(cls) -> dict:
123
94
@classmethod
124
95
def get_current_url (cls ) -> dict :
125
96
"""Generates the command to get the current URL of the page."""
126
- return cls . evaluate_js ('window.location.href' )
97
+ return RuntimeCommands . evaluate_script ('window.location.href' )
127
98
128
99
@classmethod
129
100
def find_element (
@@ -184,16 +155,6 @@ def resolve_node(cls, node_id: int) -> dict:
184
155
"""Generates the command to resolve a specific DOM node."""
185
156
return cls ._create_command (cls .RESOLVE_NODE_TEMPLATE , node_id = node_id )
186
157
187
- @classmethod
188
- def evaluate_js (cls , expression : str ) -> dict :
189
- """Generates the command to evaluate JavaScript code."""
190
- command = copy .deepcopy (cls .EVALUATE_TEMPLATE )
191
- command ['params' ] = {
192
- 'expression' : expression ,
193
- 'returnByValue' : False ,
194
- }
195
- return command
196
-
197
158
@classmethod
198
159
def _create_command (
199
160
cls ,
@@ -230,7 +191,7 @@ def _find_element_by_xpath(cls, xpath: str, object_id: str) -> dict:
230
191
escaped_value = xpath .replace ('"' , '\\ "' )
231
192
if object_id :
232
193
command = cls ._create_command (
233
- cls .CALL_FUNCTION_ON_TEMPLATE , object_id = object_id
194
+ RuntimeCommands .CALL_FUNCTION_ON_TEMPLATE , object_id = object_id
234
195
)
235
196
command ['params' ]['functionDeclaration' ] = (
236
197
'function() {'
@@ -241,7 +202,7 @@ def _find_element_by_xpath(cls, xpath: str, object_id: str) -> dict:
241
202
'}'
242
203
)
243
204
else :
244
- command = cls ._create_command (cls .EVALUATE_TEMPLATE )
205
+ command = cls ._create_command (RuntimeCommands .EVALUATE_TEMPLATE )
245
206
command ['params' ]['expression' ] = (
246
207
'var element = document.evaluate('
247
208
f'"{ escaped_value } ", document, null, '
@@ -268,7 +229,7 @@ def _find_elements_by_xpath(cls, xpath: str, object_id: str) -> dict:
268
229
escaped_value = xpath .replace ('"' , '\\ "' )
269
230
if object_id :
270
231
command = cls ._create_command (
271
- cls .CALL_FUNCTION_ON_TEMPLATE , object_id = object_id
232
+ RuntimeCommands .CALL_FUNCTION_ON_TEMPLATE , object_id = object_id
272
233
)
273
234
command ['params' ]['functionDeclaration' ] = (
274
235
'function() {'
@@ -284,7 +245,7 @@ def _find_elements_by_xpath(cls, xpath: str, object_id: str) -> dict:
284
245
'}'
285
246
)
286
247
else :
287
- command = cls ._create_command (cls .EVALUATE_TEMPLATE )
248
+ command = cls ._create_command (RuntimeCommands .EVALUATE_TEMPLATE )
288
249
command ['params' ]['expression' ] = (
289
250
'var elements = document.evaluate('
290
251
f'"{ escaped_value } ", document, null, '
0 commit comments