Skip to content

Commit 77a67ad

Browse files
committed
feat: refactor WebElement methods to use a unified naming convention
1 parent 433b2fc commit 77a67ad

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

pydoll/elements/web_element.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ async def get_bounds_using_js(self) -> dict[str, int]:
130130
131131
Returns coordinates relative to viewport (alternative to bounds property).
132132
"""
133-
response = await self._execute_script(Scripts.BOUNDS, return_by_value=True)
133+
response = await self.execute_script(Scripts.BOUNDS, return_by_value=True)
134134
return json.loads(response['result']['result']['value'])
135135

136136
async def get_parent_element(self) -> 'WebElement':
137137
"""Element's parent element."""
138-
result = await self._execute_script(Scripts.GET_PARENT_NODE)
138+
result = await self.execute_script(Scripts.GET_PARENT_NODE)
139139
if not self._has_object_id_key(result):
140140
raise ElementNotFound(f'Parent element not found for element: {self}')
141141

@@ -195,14 +195,12 @@ async def wait_until(
195195
WaitElementTimeout: If the condition is not met within ``timeout``.
196196
"""
197197
checks_map = [
198-
(is_visible, self._is_element_visible),
199-
(is_interactable, self._is_element_interactable),
198+
(is_visible, self.is_visible),
199+
(is_interactable, self.is_interactable),
200200
]
201201
checks = [func for flag, func in checks_map if flag]
202202
if not checks:
203-
raise ValueError(
204-
'At least one of is_visible or is_interactable must be True'
205-
)
203+
raise ValueError('At least one of is_visible or is_interactable must be True')
206204

207205
condition_parts = []
208206
if is_visible:
@@ -219,9 +217,7 @@ async def wait_until(
219217
return
220218

221219
if timeout and loop.time() - start_time > timeout:
222-
raise WaitElementTimeout(
223-
f'Timed out waiting for element to become {condition_msg}'
224-
)
220+
raise WaitElementTimeout(f'Timed out waiting for element to become {condition_msg}')
225221

226222
await asyncio.sleep(0.5)
227223

@@ -242,10 +238,10 @@ async def click_using_js(self):
242238

243239
await self.scroll_into_view()
244240

245-
if not await self._is_element_visible():
241+
if not await self.is_visible():
246242
raise ElementNotVisible()
247243

248-
result = await self._execute_script(Scripts.CLICK, return_by_value=True)
244+
result = await self.execute_script(Scripts.CLICK, return_by_value=True)
249245
clicked = result['result']['result']['value']
250246
if not clicked:
251247
raise ElementNotInteractable()
@@ -274,7 +270,7 @@ async def click(
274270
if self._is_option_tag():
275271
return await self._click_option_tag()
276272

277-
if not await self._is_element_visible():
273+
if not await self.is_visible():
278274
raise ElementNotVisible()
279275

280276
await self.scroll_into_view()
@@ -410,24 +406,22 @@ async def _click_option_tag(self):
410406
)
411407
)
412408

413-
async def _is_element_visible(self):
409+
async def is_visible(self):
414410
"""Check if element is visible using comprehensive JavaScript visibility test."""
415-
result = await self._execute_script(Scripts.ELEMENT_VISIBLE, return_by_value=True)
411+
result = await self.execute_script(Scripts.ELEMENT_VISIBLE, return_by_value=True)
416412
return result['result']['result']['value']
417413

418-
async def _is_element_on_top(self):
414+
async def is_on_top(self):
419415
"""Check if element is topmost at its center point (not covered by overlays)."""
420-
result = await self._execute_script(Scripts.ELEMENT_ON_TOP, return_by_value=True)
416+
result = await self.execute_script(Scripts.ELEMENT_ON_TOP, return_by_value=True)
421417
return result['result']['result']['value']
422418

423-
async def _is_element_interactable(self):
419+
async def is_interactable(self):
424420
"""Check if element is interactable based on visibility and position."""
425-
result = await self._execute_script(
426-
Scripts.ELEMENT_INTERACTIVE, return_by_value=True
427-
)
421+
result = await self.execute_script(Scripts.ELEMENT_INTERACTIVE, return_by_value=True)
428422
return result['result']['result']['value']
429423

430-
async def _execute_script(self, script: str, return_by_value: bool = False):
424+
async def execute_script(self, script: str, return_by_value: bool = False):
431425
"""
432426
Execute JavaScript in element context.
433427

0 commit comments

Comments
 (0)