symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.91k stars 213 forks source link

Click label when checkbox is obscured. #557

Open Rootie opened 2 years ago

Rootie commented 2 years ago

In some CSS frameworks (e.g. Bootstrap 4) it is possible to use custom checkbox designs. They hide the actual input element behind the label element. When submitting such a form an exception is generated:

Facebook\WebDriver\Exception\ElementClickInterceptedException : Element \ is not clickable at point (23,422) because another element \

In such a case it would be possible to automatically click the label to set the checkbox value. As a proof of concept i modified src/Client.php submit function and replaced $form->get($field)->setValue($value); (line 217) with

                try
                {
                    $formField->setValue($value);
                }
                catch (ElementClickInterceptedException $e)
                {
                    if (!($formField instanceof ChoiceFormField && $formField->getName() !== ''))
                        throw $e;
                    $formElement = $this->webDriver->findElement(WebDriverBy::cssSelector('input[name="' . $formField->getName() . '"]'));
                    $id = $formElement->getAttribute('id');
                    if (!$id)
                        throw $e;

                    $label = $this->webDriver->findElement(WebDriverBy::cssSelector('label[for=' . $id . ']'));
                    if (!$label)
                        throw $e;
                        $label->click();
                }

Would such a behavior be accepted?