Nine pages per language (home, description, install, one page per lecture step with its screenshot and what was gained, appendix) plus the sidebar. Doxygen now runs without warnings. The publish workflow is the framework template, unchanged. Task: MIL-005#1 Task: MIL-005#2 Task: MIL-005#3 Task: MIL-005#4 Task: MIL-005#5 Closes #24 Closes #25 Closes #26 Closes #27 Closes #28
28 lines
1.2 KiB
Markdown
28 lines
1.2 KiB
Markdown
# Step 2: click the cookie
|
|
|
|
🌐 **English** · [Dansk](Step-2-Click-The-Cookie-da) · [Bahasa Melayu](Step-2-Click-The-Cookie-ms)
|
|
|
|
`click_cookie` clicks the big cookie a number of times. After 15 clicks the screenshot shows the counter and the first cookies in the bakery.
|
|
|
|
**Screenshot**
|
|
|
|

|
|
|
|
**Function**
|
|
|
|
```python
|
|
def click_cookie(game: GamePort, times: int = 1) -> None:
|
|
if times < 0:
|
|
raise ValueError(f"times must not be negative, got {times}")
|
|
for _ in range(times):
|
|
game.click_element(BIG_COOKIE_ID)
|
|
```
|
|
|
|
## What we gained
|
|
|
|
- **A real click, not a script click.** The game ignores synthetic clicks above about 3 per second but accepts about 50 per second from a real click, so `SeleniumGame` always uses `element.click()`.
|
|
- **Guard the input.** A negative number of clicks raises `ValueError`, and zero clicks is allowed; both are tested.
|
|
- **Retry when the page changes.** The game redraws its page often, so a click that hits a stale element is tried again a few times.
|
|
|
|
Next: [Step 3: read the count](Step-3-Read-The-Count)
|