Skip to content

Commit 09a7833

Browse files
committed
feat: add getAttribute method to Element class for retrieving element attributes
1 parent 084b3bc commit 09a7833

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/Playwright/Element.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,21 @@ public function uncheck(): void
7575
// read all messages to clear the response
7676
}
7777
}
78+
79+
/**
80+
* Get the Attribute of the element.
81+
*/
82+
public function getAttribute(string $attribute): ?string
83+
{
84+
$response = Client::instance()->execute($this->guid, 'getAttribute', ['name' => $attribute]);
85+
86+
/** @var array{result: array{value: string|null}} $message */
87+
foreach ($response as $message) {
88+
if (isset($message['result']['value'])) {
89+
return $message['result']['value'];
90+
}
91+
}
92+
93+
return null;
94+
}
7895
}

0 commit comments

Comments
 (0)