Skip to content

Commit d9c98a6

Browse files
committed
feat: add methods to find elements by role, test ID, alt text, label, placeholder, text, and title in Page class
1 parent d0aff66 commit d9c98a6

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

src/Playwright/Page.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,64 @@ public function querySelector(string $selector): ?Element
128128
return $this->frame->querySelector($selector);
129129
}
130130

131+
/**
132+
* Finds an element by the specified role.
133+
*
134+
* @param array<string, string|bool> $params
135+
*/
136+
public function getByRole(string $role, array $params): ?Element
137+
{
138+
return $this->frame->getByRole($role, $params);
139+
}
140+
141+
/**
142+
* Finds an element by test ID.
143+
*/
144+
public function getByTestId(string $testId): ?Element
145+
{
146+
return $this->frame->getByTestId($testId);
147+
}
148+
149+
/**
150+
* Finds an element by alt text.
151+
*/
152+
public function getByAltText(string $text, bool $exact = false): ?Element
153+
{
154+
return $this->frame->getByAltText($text, $exact);
155+
}
156+
157+
/**
158+
* Finds an element by label text.
159+
*/
160+
public function getByLabel(string $text, bool $exact = false): ?Element
161+
{
162+
return $this->frame->getByLabel($text, $exact);
163+
}
164+
165+
/**
166+
* Finds an element by placeholder text.
167+
*/
168+
public function getByPlaceholder(string $text, bool $exact = false): ?Element
169+
{
170+
return $this->frame->getByPlaceholder($text, $exact);
171+
}
172+
173+
/**
174+
* Finds an element by its text content.
175+
*/
176+
public function getByText(string $text, bool $exact = false): ?Element
177+
{
178+
return $this->frame->getByText($text, $exact);
179+
}
180+
181+
/**
182+
* Finds an element by its title attribute.
183+
*/
184+
public function getByTitle(string $text, bool $exact = false): ?Element
185+
{
186+
return $this->frame->getByTitle($text, $exact);
187+
}
188+
131189
/**
132190
* Returns the page's title.
133191
*/

0 commit comments

Comments
 (0)