From c36aada9b4f3a9f0418020db19d4409215c331ca Mon Sep 17 00:00:00 2001 From: Herve Donner Date: Sat, 10 Aug 2024 16:07:26 +0200 Subject: [PATCH 1/3] Add missing mouseover for select and radio elements before click. --- src/Selenium2Driver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 463479be..2eaa9184 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -1188,7 +1188,7 @@ private function selectRadioValue(Element $element, string $value): void { // short-circuit when we already have the right button of the group to avoid XPath queries if ($element->attribute('value') === $value) { - $element->click(); + $this->clickOnElement($element); return; } @@ -1230,7 +1230,7 @@ private function selectRadioValue(Element $element, string $value): void throw new DriverException($message, 0, $e); } - $input->click(); + $this->clickOnElement($input); } /** @@ -1242,6 +1242,7 @@ private function selectOptionOnElement(Element $element, string $value, bool $mu // The value of an option is the normalized version of its text when it has no value attribute $optionQuery = sprintf('.//option[@value = %s or (not(@value) and normalize-space(.) = %s)]', $escapedValue, $escapedValue); $option = $element->element('xpath', $optionQuery); + $this->doMouseOver($element); if ($multiple || !$element->attribute('multiple')) { if (!$option->selected()) { From faed6183700af791b12eb484797727d5ce7939d1 Mon Sep 17 00:00:00 2001 From: Herve Donner Date: Tue, 20 Aug 2024 02:56:58 +0200 Subject: [PATCH 2/3] Reproduce issue (caused by size attribute on form elements?). --- tests/Custom/LargePageClickTest.php | 47 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/Custom/LargePageClickTest.php b/tests/Custom/LargePageClickTest.php index 17a16960..4705eeed 100644 --- a/tests/Custom/LargePageClickTest.php +++ b/tests/Custom/LargePageClickTest.php @@ -8,14 +8,48 @@ class LargePageClickTest extends TestCase { public function testLargePageClick(): void { - $this->getSession()->visit($this->pathTo('/multi_input_form.html')); + $this->getSession()->visit($this->pathTo('/advanced_form.html')); + // @todo Why is size attribute causing ElementClickIntercepted errors? + $this->getSession()->executeScript('document.querySelector("input[name=\'first_name\']").setAttribute("size", 200);'); - // Add a large amount of br tags so that the button is not in view. + // Add a large amount of br tags so that form elements are not in view. $this->makePageLong(); $page = $this->getSession()->getPage(); + + // Test select focus. + $this->scrollToTop(); + $page->selectFieldOption('select_number', 'thirty'); + + // Test radio button focus. + $this->scrollToTop(); + $page->selectFieldOption('sex', 'm'); + + // Test checkboxes focus. + $this->scrollToTop(); + $page->uncheckField('mail_list'); + $this->scrollToTop(); + $page->checkField('agreement'); + + // Test button focus and submit. + $this->scrollToTop(); $page->pressButton('Register'); - $this->assertStringContainsString('no file', $page->getContent()); + + $expected = <<assertStringContainsString($expected, $page->getContent()); } public function testDragDrop(): void @@ -47,4 +81,11 @@ private function makePageLong(): void { $this->getSession()->executeScript($script); } + /** + * Scrolls to the top of the page. + */ + private function scrollToTop(): void { + $this->getSession()->executeScript('window.scrollTo(0, 0);'); + } + } From bdb6b464d6fbbc3534791e5e80f2420e779b8561 Mon Sep 17 00:00:00 2001 From: Herve Donner Date: Tue, 20 Aug 2024 03:01:58 +0200 Subject: [PATCH 3/3] Looks like scrollIntoView block: 'center' fixes it?? --- src/Selenium2Driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 2eaa9184..2964038c 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -953,7 +953,7 @@ public function mouseOver(string $xpath) private function scrollElementIntoView(Element $element): void { $script = <<