/** * Method to select elements, usinga sleector (css, xpath, etc.). * * @param By $by Indicates how to search for elements * * @return array An array of elements */ public function elements(By $by, $from = null) { if (null === $from) { $uri = 'elements'; } else { $uri = 'element/' . $from->getId() . '/elements'; } $response = $this->request('POST', $uri, json_encode($by->toArray())); $data = json_decode($response->getContent(), true); if (!isset($data['value'])) { throw new LibraryException('Missing key value'); } $elements = array(); foreach ($data['value'] as $val) { $elements[] = new Element($this, $val['ELEMENT']); } return $elements; }