@@ -77,6 +77,9 @@ class WebdriverClassicDriver extends CoreDriver
7777
7878 private DesiredCapabilities $ desiredCapabilities ;
7979
80+ /**
81+ * @var array{script?: null|numeric, implicit?: null|numeric, page?: null|numeric}
82+ */
8083 private array $ timeouts = [];
8184
8285 private string $ webDriverHost ;
@@ -85,6 +88,7 @@ class WebdriverClassicDriver extends CoreDriver
8588
8689 /**
8790 * @param string $browserName One of 'edge', 'firefox', 'chrome' or any one of {@see WebDriverBrowserType} constants.
91+ * @param array<string, mixed> $desiredCapabilities
8892 */
8993 public function __construct (
9094 string $ browserName = self ::DEFAULT_BROWSER ,
@@ -262,7 +266,7 @@ public function getWindowNames(): array
262266
263267 public function getWindowName (): string
264268 {
265- $ name = ( string ) $ this ->evaluateScript ('window.name ' );
269+ $ name = $ this -> getAsString ( $ this ->evaluateScript ('window.name ' ), ' Window name ' );
266270
267271 if ($ name === '' ) {
268272 $ name = self ::W3C_WINDOW_HANDLE_PREFIX . $ this ->getWebDriver ()->getWindowHandle ();
@@ -299,22 +303,22 @@ public function getText(
299303 return str_replace (
300304 ["\r\n" , "\r" , "\n" ],
301305 ' ' ,
302- $ this ->getElementDomProperty ($ this ->findElement ($ xpath ), 'innerText ' )
306+ $ this ->getAsString ( $ this -> getElementDomProperty ($ this ->findElement ($ xpath ), 'innerText ' ), ' The element \' s innerText ' )
303307 );
304308 }
305309
306310 public function getHtml (
307311 #[Language('XPath ' )]
308312 string $ xpath
309313 ): string {
310- return $ this ->getElementDomProperty ($ this ->findElement ($ xpath ), 'innerHTML ' );
314+ return $ this ->getAsString ( $ this -> getElementDomProperty ($ this ->findElement ($ xpath ), 'innerHTML ' ), ' The element \' s innerHTML ' );
311315 }
312316
313317 public function getOuterHtml (
314318 #[Language('XPath ' )]
315319 string $ xpath
316320 ): string {
317- return $ this ->getElementDomProperty ($ this ->findElement ($ xpath ), 'outerHTML ' );
321+ return $ this ->getAsString ( $ this -> getElementDomProperty ($ this ->findElement ($ xpath ), 'outerHTML ' ), ' The element \' s outerHTML ' );
318322 }
319323
320324 public function getAttribute (
@@ -326,9 +330,13 @@ public function getAttribute(
326330 // so we cannot use webdriver api for this. See also: https://w3c.github.io/webdriver/#dfn-get-element-attribute
327331 $ escapedName = $ this ->jsonEncode ($ name , 'get attribute ' , 'attribute name ' );
328332 $ script = "return arguments[0].getAttribute( $ escapedName) " ;
329- return $ this ->executeJsOnXpath ($ xpath , $ script );
333+ $ result = $ this ->executeJsOnXpath ($ xpath , $ script );
334+ return $ result === null ? null : $ this ->getAsString ($ result , "The element's $ name attribute " );
330335 }
331336
337+ /**
338+ * @return array<array-key, mixed>|bool|mixed|string|null
339+ */
332340 public function getValue (
333341 #[Language('XPath ' )]
334342 string $ xpath
@@ -369,6 +377,9 @@ public function getValue(
369377 }
370378 }
371379
380+ /**
381+ * @param array<array-key, mixed>|bool|mixed|string|null $value
382+ */
372383 public function setValue (
373384 #[Language('XPath ' )]
374385 string $ xpath ,
@@ -386,7 +397,7 @@ public function setValue(
386397 if (is_array ($ value )) {
387398 $ this ->deselectAllOptions ($ element );
388399 foreach ($ value as $ option ) {
389- $ this ->selectOptionOnElement ($ element , $ option , true );
400+ $ this ->selectOptionOnElement ($ element , $ this -> getAsString ( $ option, ' Option value ' ) , true );
390401 }
391402 return ;
392403 }
@@ -736,7 +747,7 @@ public function getWebDriverSessionId(): ?string
736747 /**
737748 * Sets the timeouts to apply to the webdriver session
738749 *
739- * @param array $timeouts The session timeout settings: Array of {script, implicit, page} => time in milliseconds
750+ * @param array{script?: numeric, implicit?: numeric, page?: numeric} $timeouts The session timeout settings: Array of {script, implicit, page} => time in milliseconds
740751 * @throws DriverException
741752 * @api
742753 */
@@ -785,6 +796,8 @@ private function getNormalisedBrowserName(): string
785796 /**
786797 * Detect and assign appropriate browser capabilities
787798 *
799+ * @param array<string, mixed> $desiredCapabilities
800+ *
788801 * @see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
789802 */
790803 private function initCapabilities (array $ desiredCapabilities ): DesiredCapabilities
@@ -1227,5 +1240,20 @@ private function getElementDomProperty(RemoteWebElement $element, string $proper
12271240 }
12281241 }
12291242
1243+ /**
1244+ * @param mixed $value
1245+ */
1246+ private function getAsString ($ value , string $ name ): string
1247+ {
1248+ if (!is_scalar ($ value )) {
1249+ $ actualType = gettype ($ value );
1250+ throw new \RuntimeException (
1251+ "$ name should be a string or at least a scalar value, but received ` $ actualType` instead "
1252+ );
1253+ }
1254+
1255+ return (string )$ value ;
1256+ }
1257+
12301258 // </editor-fold>
12311259}
0 commit comments