Beispiel #1
0
 /**
  * @return Form
  *
  * @throws UnexpectedElementException If the form attribute does not target a form.
  * @throws NoSuchElementException     IF the element does not belong to a form.
  */
 public function getForm()
 {
     $element = $this->element->getDomElement();
     $document = $element->ownerDocument;
     if ($element->hasAttribute('form')) {
         $form = $document->getElementById($element->getAttribute('form'));
         if (!$form) {
             throw new NoSuchElementException('Element has a form attribute that targets an id that does not exist');
         }
         if (strtolower($form->tagName) != 'form') {
             throw new UnexpectedElementException('Element has a form attribute that does not target a form');
         }
         $form = new Element($form);
     } else {
         $form = $this->element->getParent('form');
     }
     return Form::create($form);
 }
Beispiel #2
0
 /**
  * Submits a form.
  *
  * If called on a form, submits it.
  * If called on any form element, submits its form.
  * If called on any other element, throws an exception.
  *
  * The element must contain exactly one node, else this method will throw an exception.
  * The element must belong to the current document, else this method will throw an exception.
  *
  * @param Target $target
  *
  * @return static
  *
  * @throws Exception\BrowserException
  * @throws Exception\StaleElementReferenceException If the element does not belong to the current page.
  */
 public function submit(Target $target)
 {
     $element = $target->getTargetElement($this);
     if ($element->is('form')) {
         return $this->submitForm(Wrapper\Form::create($element));
     }
     return $this->submit($element->getParent('form'));
     if ($element instanceof Wrapper\FormControl) {
         if (!($form = $element->getForm())) {
             throw new UnexpectedElementException('The element has no form and cannot be submitted');
         }
         return $this->submit($form);
     }
     throw new Exception\BrowserException('Cannot submit the given element');
 }