panther
panther copied to clipboard
Click label when checkbox is obscured.
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 <input id="x" class="custom-control-input" name="y" type="checkbox"> is not clickable at point (23,422) because another element <label class="custom-control-label"> obscures it
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?