From 17785b2aeed74a03ab9c1eb6a454f59ecd29cd18 Mon Sep 17 00:00:00 2001 From: Sebastian Hensel Date: Fri, 21 Nov 2014 11:57:42 +0100 Subject: [PATCH] Throw Exception if Element is missing and typo --- src/Nearsoft/SeleniumClient/WebDriver.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Nearsoft/SeleniumClient/WebDriver.php b/src/Nearsoft/SeleniumClient/WebDriver.php index 8ad030c..78b98af 100644 --- a/src/Nearsoft/SeleniumClient/WebDriver.php +++ b/src/Nearsoft/SeleniumClient/WebDriver.php @@ -504,8 +504,8 @@ public function screenshot($overrideScreenshotsDirectory = null) * @throws Http\SeleniumNoSuchElementException * @return Nearsoft\SeleniumClient\WebElement */ - public function findElement(By $locator, $polling = false, $elementId = -1) - { + public function findElement(By $locator, $polling = false, $elementId = -1) + { if (strpos($locator->getStrategy(), 'js selector ') === 0) { $result = $this->findElements($locator, $polling, $elementId); if (!$result) { @@ -513,7 +513,7 @@ public function findElement(By $locator, $polling = false, $elementId = -1) } return $result[0]; } else { - $params = array ('using' => $locator->getStrategy(), 'value' => $locator->getSelectorValue()); + $params = array ('using' => $locator->getStrategy(), 'value' => $locator->getSelectorValue()); if ($elementId < 0) { $command = new Commands\Command($this, 'element', $params); } @@ -522,10 +522,13 @@ public function findElement(By $locator, $polling = false, $elementId = -1) $command = new Commands\Command($this, 'element_in_element', $params, array('element_id' => $elementId)); } $command->setPolling($polling); - $results = $command->execute(); + $results = $command->execute(); + if (!$results['value']['ELEMENT']) { + throw new Exceptions\NoSuchElement(); + } return new WebElement($this, $results['value']['ELEMENT']); } - } + } /** * Gets elements within current page