Skip to content

Commit 199315d

Browse files
Merge branch 'main' into main
2 parents 3c7a912 + 41d8406 commit 199315d

File tree

5 files changed

+125
-9
lines changed

5 files changed

+125
-9
lines changed

pydoll/browser/chromium/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ async def new_tab(self, url: str = '', browser_context_id: Optional[str] = None)
223223
"""
224224
response: CreateTargetResponse = await self._execute_command(
225225
TargetCommands.create_target(
226-
url=url,
227226
browser_context_id=browser_context_id,
228227
)
229228
)
@@ -237,6 +236,8 @@ async def new_tab(self, url: str = '', browser_context_id: Optional[str] = None)
237236
# Inject fingerprint spoofing JavaScript if enabled
238237
await self._setup_fingerprint_for_tab(tab)
239238

239+
if url: await tab.go_to(url)
240+
240241
return tab
241242

242243
async def get_targets(self) -> list[TargetInfo]:

pydoll/commands/target_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def create_browser_context(
141141

142142
@staticmethod
143143
def create_target( # noqa: PLR0913, PLR0917
144-
url: str,
144+
url: str = 'about:blank',
145145
left: Optional[int] = None,
146146
top: Optional[int] = None,
147147
width: Optional[int] = None,

pydoll/elements/mixins/find_elements_mixin.py

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from typing import TYPE_CHECKING, Optional, TypeVar, Union
2+
from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union, overload
33

44
from pydoll.commands import (
55
DomCommands,
@@ -44,6 +44,76 @@ class FindElementsMixin:
4444
complex location logic themselves.
4545
"""
4646

47+
@overload
48+
async def find(
49+
self,
50+
id: Optional[str] = ...,
51+
class_name: Optional[str] = ...,
52+
name: Optional[str] = ...,
53+
tag_name: Optional[str] = ...,
54+
text: Optional[str] = ...,
55+
timeout: int = ...,
56+
find_all: Literal[False] = False,
57+
raise_exc: Literal[True] = True,
58+
**attributes: dict[str, str],
59+
) -> 'WebElement': ...
60+
61+
@overload
62+
async def find(
63+
self,
64+
id: Optional[str] = ...,
65+
class_name: Optional[str] = ...,
66+
name: Optional[str] = ...,
67+
tag_name: Optional[str] = ...,
68+
text: Optional[str] = ...,
69+
timeout: int = ...,
70+
find_all: Literal[True] = True,
71+
raise_exc: Literal[True] = True,
72+
**attributes: dict[str, str],
73+
) -> list['WebElement']: ...
74+
75+
@overload
76+
async def find(
77+
self,
78+
id: Optional[str] = ...,
79+
class_name: Optional[str] = ...,
80+
name: Optional[str] = ...,
81+
tag_name: Optional[str] = ...,
82+
text: Optional[str] = ...,
83+
timeout: int = ...,
84+
find_all: Literal[True] = True,
85+
raise_exc: Literal[False] = False,
86+
**attributes: dict[str, str],
87+
) -> Optional[list['WebElement']]: ...
88+
89+
@overload
90+
async def find(
91+
self,
92+
id: Optional[str] = ...,
93+
class_name: Optional[str] = ...,
94+
name: Optional[str] = ...,
95+
tag_name: Optional[str] = ...,
96+
text: Optional[str] = ...,
97+
timeout: int = ...,
98+
find_all: Literal[False] = False,
99+
raise_exc: Literal[False] = False,
100+
**attributes: dict[str, str],
101+
) -> Optional['WebElement']: ...
102+
103+
@overload
104+
async def find(
105+
self,
106+
id: Optional[str] = ...,
107+
class_name: Optional[str] = ...,
108+
name: Optional[str] = ...,
109+
tag_name: Optional[str] = ...,
110+
text: Optional[str] = ...,
111+
timeout: int = ...,
112+
find_all: bool = ...,
113+
raise_exc: bool = ...,
114+
**attributes: dict[str, str],
115+
) -> Union['WebElement', list['WebElement'], None]: ...
116+
47117
async def find( # noqa: PLR0913, PLR0917
48118
self,
49119
id: Optional[str] = None,
@@ -101,6 +171,51 @@ async def find( # noqa: PLR0913, PLR0917
101171
by, value, timeout=timeout, find_all=find_all, raise_exc=raise_exc
102172
)
103173

174+
@overload
175+
async def query(
176+
self,
177+
expression: str,
178+
timeout: int = ...,
179+
find_all: Literal[False] = False,
180+
raise_exc: Literal[True] = True,
181+
) -> 'WebElement': ...
182+
183+
@overload
184+
async def query(
185+
self,
186+
expression: str,
187+
timeout: int = ...,
188+
find_all: Literal[False] = False,
189+
raise_exc: Literal[False] = False,
190+
) -> Optional['WebElement']: ...
191+
192+
@overload
193+
async def query(
194+
self,
195+
expression: str,
196+
timeout: int = ...,
197+
find_all: Literal[True] = True,
198+
raise_exc: Literal[True] = True,
199+
) -> list['WebElement']: ...
200+
201+
@overload
202+
async def query(
203+
self,
204+
expression: str,
205+
timeout: int = ...,
206+
find_all: Literal[True] = True,
207+
raise_exc: Literal[False] = False,
208+
) -> Optional[list['WebElement']]: ...
209+
210+
@overload
211+
async def query(
212+
self,
213+
expression: str,
214+
timeout: int = ...,
215+
find_all: bool = ...,
216+
raise_exc: bool = ...,
217+
) -> Union['WebElement', list['WebElement'], None]: ...
218+
104219
async def query(
105220
self, expression: str, timeout: int = 0, find_all: bool = False, raise_exc: bool = True
106221
) -> Union['WebElement', list['WebElement'], None]:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ target-version = "py310"
4343
[tool.ruff.lint]
4444
preview = true
4545
select = ['I', 'F', 'E', 'W', 'PL', 'PT']
46+
ignore = ['E701']
4647
exclude = ['tests', 'tests/*']
4748

4849
[tool.ruff.format]

tests/test_browser/test_browser_base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,19 +566,18 @@ async def test_multiple_tab_handling(mock_browser):
566566
# Simulate getting multiple tabs
567567
mock_browser._connection_handler.execute_command.side_effect = [
568568
{'result': {'targetId': 'tab1'}},
569-
{'result': {'targetId': 'tab2'}}
569+
{'result': {'targetId': 'tab2'}},
570570
]
571571

572-
tab1 = await mock_browser.new_tab(url='https://example1.com')
573-
tab2 = await mock_browser.new_tab(url='https://example2.com')
572+
tab1 = await mock_browser.new_tab()
573+
tab2 = await mock_browser.new_tab()
574574

575575
assert tab1._target_id == 'tab1'
576576
assert tab2._target_id == 'tab2'
577577

578578
# Verify that correct calls were made
579579
calls = mock_browser._connection_handler.execute_command.call_args_list
580-
assert calls[0][0][0] == TargetCommands.create_target('https://example1.com', None)
581-
assert calls[1][0][0] == TargetCommands.create_target('https://example2.com', None)
580+
assert len(calls) == 2
582581

583582

584583
# New tests for _get_valid_tab_id
@@ -1194,7 +1193,7 @@ async def test_get_opened_tabs_integration_with_new_tab(mock_browser):
11941193
}
11951194

11961195
# Create a new tab
1197-
new_tab = await mock_browser.new_tab('https://example.com')
1196+
new_tab = await mock_browser.new_tab()
11981197
assert new_tab._target_id == 'new_tab_1'
11991198

12001199
# Mock updated targets after tab creation

0 commit comments

Comments
 (0)