Skip to content

Commit 76b7535

Browse files
committed
fix: enhance DOM command methods and rename for clarity and consistency
1 parent 5b358e1 commit 76b7535

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pydoll/commands/dom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def scroll_into_view(
5151
)
5252

5353
@classmethod
54-
def get_outer_html(cls, node_id: int) -> dict:
54+
def get_outer_html(cls, node_id: int = None, object_id: str = '') -> dict:
5555
"""Generates the command to get the outer HTML"""
56-
return cls._create_command(cls.GET_OUTER_HTML, node_id=node_id)
56+
return cls._create_command(
57+
cls.GET_OUTER_HTML, node_id=node_id, object_id=object_id
58+
)
5759

5860
@classmethod
5961
def dom_document(cls) -> dict:

pydoll/element.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,16 @@ async def inner_html(self) -> str:
134134
Returns:
135135
str: The inner HTML of the element.
136136
"""
137-
command = DomCommands.get_outer_html(self._node['nodeId'])
137+
if self._search_method == By.XPATH:
138+
command = DomCommands.get_outer_html(
139+
object_id=self._node['objectId']
140+
)
141+
else:
142+
command = DomCommands.get_outer_html(self._node['nodeId'])
138143
response = await self._execute_command(command)
139144
return response['result']['outerHTML']
140145

141-
async def get_bounds_by_js(self) -> list:
146+
async def get_bounds_using_js(self) -> list:
142147
"""
143148
Retrieves the bounding box of the element using JavaScript.
144149
@@ -197,9 +202,7 @@ async def get_element_text(self) -> str:
197202
Returns:
198203
str: The text of the element.
199204
"""
200-
command = DomCommands.get_outer_html(self._node['nodeId'])
201-
response = await self._execute_command(command)
202-
outer_html = response['result']['outerHTML']
205+
outer_html = await self.inner_html
203206
soup = BeautifulSoup(outer_html, 'html.parser')
204207
text_inside = soup.get_text(strip=True)
205208
return text_inside
@@ -230,7 +233,7 @@ async def scroll_into_view(self):
230233
)
231234
await self._execute_command(command)
232235

233-
async def click(self):
236+
async def click_using_js(self):
234237
if self._is_option_tag():
235238
return await self.click_option_tag()
236239

@@ -250,7 +253,7 @@ async def click(self):
250253
'Element is not interactable.'
251254
)
252255

253-
async def realistic_click(self, x_offset: int = 0, y_offset: int = 0):
256+
async def click(self, x_offset: int = 0, y_offset: int = 0):
254257
if not await self._is_element_visible():
255258
raise exceptions.ElementNotVisible(
256259
'Element is not visible on the page.'
@@ -269,7 +272,7 @@ async def realistic_click(self, x_offset: int = 0, y_offset: int = 0):
269272
position_to_click[1] + y_offset,
270273
)
271274
except IndexError:
272-
element_bounds = await self.get_bounds_by_js()
275+
element_bounds = await self.get_bounds_using_js()
273276
element_bounds = json.loads(element_bounds)
274277
position_to_click = (
275278
element_bounds['x'] + element_bounds['width'] / 2,

0 commit comments

Comments
 (0)