Skip to content

Commit 7a06064

Browse files
committed
docs: update READMEs and documentation for new methods
1 parent 7f27722 commit 7a06064

File tree

4 files changed

+86
-12
lines changed

4 files changed

+86
-12
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,40 @@ We believe that powerful automation shouldn't require you to become an expert in
4747

4848
## What's New
4949

50+
### WebElement: state waiting and new public APIs
51+
52+
- New `wait_until(...)` on `WebElement` to await element states with minimal code:
53+
54+
```python
55+
# Wait until it becomes visible OR the timeout expires
56+
await element.wait_until(is_visible=True, timeout=5)
57+
58+
# Wait until it becomes interactable (visible, on top, receiving pointer events)
59+
await element.wait_until(is_interactable=True, timeout=10)
60+
```
61+
62+
- Methods now public on `WebElement`:
63+
- `is_visible()`
64+
- Checks that the element has a visible area (> 0), isn’t hidden by CSS and is in the viewport (after `scroll_into_view()` when needed). Useful pre-check before interactions.
65+
- `is_interactable()`
66+
- “Click-ready” state: combines visibility, enabledness and pointer-event hit testing. Ideal for robust flows that avoid lost clicks.
67+
- `is_on_top()`
68+
- Verifies the element is the top hit-test target at the intended click point, avoiding overlays.
69+
- `execute_script(script: str, return_by_value: bool = False)`
70+
- Executes JavaScript in the element’s own context (where `this` is the element). Great for fine-tuning and quick inspections.
71+
72+
```python
73+
# Visually outline the element via JS
74+
await element.execute_script("this.style.outline='2px solid #22d3ee'")
75+
76+
# Confirm states
77+
visible = await element.is_visible()
78+
interactable = await element.is_interactable()
79+
on_top = await element.is_on_top()
80+
```
81+
82+
These additions simplify waiting and state validation before clicking/typing, reducing flakiness and making automations more predictable.
83+
5084
### Browser-context HTTP requests - game changer for hybrid automation!
5185
Ever wished you could make HTTP requests that automatically inherit all your browser's session state? **Now you can!**<br>
5286
The `tab.request` property gives you a beautiful `requests`-like interface that executes HTTP calls directly in the browser's JavaScript context. This means every request automatically gets cookies, authentication headers, CORS policies, and session state, just as if the browser made the request itself.

README_zh.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ Pydoll 采用全新设计理念,从零构建,直接对接 Chrome DevTools Pr
4949

5050
## 最新功能
5151

52+
### WebElement:状态等待与新的公共 API
53+
54+
- 新增 `wait_until(...)` 用于等待元素状态,使用更简单:
55+
56+
```python
57+
# 等待元素变为可见,直到超时
58+
await element.wait_until(is_visible=True, timeout=5)
59+
60+
# 等待元素变为可交互(可见、位于顶层并可接收事件)
61+
await element.wait_until(is_interactable=True, timeout=10)
62+
```
63+
64+
- 以下 `WebElement` 方法现已公开:
65+
- `is_visible()`
66+
- 判断元素是否具有可见区域、未被 CSS 隐藏,并在需要时滚动进入视口。适用于交互前的快速校验。
67+
- `is_interactable()`
68+
- “可点击”状态:综合可见性、启用状态与指针事件命中等条件,适合构建更稳健的交互流程。
69+
- `is_on_top()`
70+
- 检查元素在点击位置是否为顶部命中目标,避免被覆盖导致点击失效。
71+
- `execute_script(script: str, return_by_value: bool = False)`
72+
- 在元素上下文中执行 JavaScript(this 指向该元素),便于细粒度调整与快速检查。
73+
74+
```python
75+
# 使用 JS 高亮元素
76+
await element.execute_script("this.style.outline='2px solid #22d3ee'")
77+
78+
# 校验状态
79+
visible = await element.is_visible()
80+
interactable = await element.is_interactable()
81+
on_top = await element.is_on_top()
82+
```
83+
84+
以上新增能力能显著简化“等待+验证”场景,降低自动化过程中的不稳定性,使用例更可预测。
85+
5286
### 浏览器上下文 HTTP 请求 - 混合自动化的游戏规则改变者!
5387
你是否曾经希望能够发出自动继承浏览器所有会话状态的 HTTP 请求?**现在你可以了!**<br>
5488
`tab.request` 属性为你提供了一个美观的 `requests` 风格接口,可在浏览器的 JavaScript 上下文中直接执行 HTTP 调用。这意味着每个请求都会自动获得 cookies、身份验证标头、CORS 策略和会话状态,就像浏览器本身发出请求一样。

public/docs/deep-dive/webelement-domain.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async def click(
217217
if self._is_option_tag():
218218
return await self.click_option_tag()
219219

220-
if not await self._is_element_visible():
220+
if not await self.is_visible():
221221
raise exceptions.ElementNotVisible(
222222
'Element is not visible on the page.'
223223
)
@@ -341,16 +341,16 @@ WebElement provides seamless integration with JavaScript for operations that req
341341

342342
```python
343343
# Execute JavaScript in the context of this element
344-
await element._execute_script("this.style.border = '2px solid red';")
344+
await element.execute_script("this.style.border = '2px solid red';")
345345

346346
# Get result from JavaScript execution
347-
visibility = await element._is_element_visible()
347+
visibility = await element.is_visible()
348348
```
349349

350350
The implementation uses the CDP Runtime domain to execute JavaScript with the element as the context:
351351

352352
```python
353-
async def _execute_script(
353+
async def execute_script(
354354
self, script: str, return_by_value: bool = False
355355
):
356356
"""
@@ -369,10 +369,13 @@ WebElement provides methods to check the element's visibility and interactabilit
369369

370370
```python
371371
# Check if element is visible
372-
is_visible = await element._is_element_visible()
372+
is_visible = await element.is_visible()
373373

374374
# Check if element is the topmost at its position
375-
is_on_top = await element._is_element_on_top()
375+
is_on_top = await element.is_on_top()
376+
377+
# Check if element is interactable
378+
is_interactable = await element.is_interactable()
376379
```
377380

378381
These verifications are crucial for reliable automation, ensuring that elements can be interacted with before attempting operations.

public/docs/zh/deep-dive/webelement-domain.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async def click(
219219
if self._is_option_tag():
220220
return await self.click_option_tag()
221221

222-
if not await self._is_element_visible():
222+
if not await self.is_visible():
223223
raise exceptions.ElementNotVisible(
224224
'Element is not visible on the page.'
225225
)
@@ -342,16 +342,16 @@ WebElement 为需要直接操作DOM的操作提供了与JavaScript的无缝集
342342

343343
```python
344344
# Execute JavaScript in the context of this element
345-
await element._execute_script("this.style.border = '2px solid red';")
345+
await element.execute_script("this.style.border = '2px solid red';")
346346

347347
# Get result from JavaScript execution
348-
visibility = await element._is_element_visible()
348+
visibility = await element.is_visible()
349349
```
350350

351351
该实现通过CDP Runtime域执行JavaScript,并将元素作为上下文:
352352

353353
```python
354-
async def _execute_script(
354+
async def execute_script(
355355
self, script: str, return_by_value: bool = False
356356
):
357357
"""
@@ -371,10 +371,13 @@ WebElement 提供了检查元素可见性和可交互性的方法:
371371

372372
```python
373373
# Check if element is visible
374-
is_visible = await element._is_element_visible()
374+
is_visible = await element.is_visible()
375375

376376
# Check if element is the topmost at its position
377-
is_on_top = await element._is_element_on_top()
377+
is_on_top = await element.is_on_top()
378+
379+
# Check if element is interactable
380+
is_interactable = await element.is_interactable()
378381
```
379382

380383
这些验证对于实现可靠的自动化至关重要,可在尝试操作前确保元素可被交互。

0 commit comments

Comments
 (0)