Skip to content

Click on link with block child silently fails #1007

@elliterate

Description

@elliterate

Given a link with a block-level child (i.e., display: block), clicking on it will silently fail. No JavaScript or navigation is triggered. (Clicking on the child, however, will work.)

System

  • Version: 0.19.0
  • Platform: macOS 10.12.6
  • Firefox: 56.0; 57.0b6; 58.0a1
  • Selenium: py/3.6.0

Testcase

test_click_link.py

import inspect
import os.path
from unittest import TestCase, main

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


_DIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))


class TestClickLink(TestCase):
    @classmethod
    def setUpClass(cls):
        capabilities = DesiredCapabilities.FIREFOX.copy()
        capabilities["marionette"] = True
        capabilities["moz:firefoxOptions"] = {"log": {"level": "trace"}}
        cls.browser = webdriver.Firefox(capabilities=capabilities)

    def setUp(self):
        self.browser.get("file://{}".format(os.path.join(_DIR, "index.html")))
        self.result = self.browser.find_element_by_id("result")

    def tearDown(self):
        self.browser.get("about:blank")

    @classmethod
    def tearDownClass(cls):
        cls.browser.quit()

    def test_click_link_without_child(self):
        link = self.browser.find_element_by_link_text("No Child")
        link.click()
        self.assertEqual(self.result.text, "Link was clicked.")

    def test_click_link_with_block_child(self):
        link = self.browser.find_element_by_link_text("Block Child")
        link.click()
        self.assertEqual(self.result.text, "Link was clicked.")

    def test_click_link_with_inline_child(self):
        link = self.browser.find_element_by_link_text("Inline Child")
        link.click()
        self.assertEqual(self.result.text, "Link was clicked.")

if __name__ == "__main__":
    main()

index.html

<html>
  <head>
    <script type="text/javascript">
      function handleClick(e) {
        e.preventDefault();
        document.querySelector("#result").innerText = "Link was clicked.";
      }
    </script>
  </head>

  <body>
    <div id="result"></div>
    <a href="#" onclick="handleClick(event)">No Child</a>
    <a href="#" onclick="handleClick(event)"><div>Block Child</div></a>
    <a href="#" onclick="handleClick(event)"><span>Inline Child</span></a>
  </body>
</html>

Stacktrace

$ python test_click_link.py
F..
======================================================================
FAIL: test_click_link_with_block_child (__main__.TestClickLink)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_click_link.py", line 39, in test_click_link_with_block_child
    self.assertEqual(self.result.text, "Link was clicked.")
AssertionError: '' != 'Link was clicked.'
+ Link was clicked.

----------------------------------------------------------------------
Ran 3 tests in 4.758s

FAILED (failures=1)

Trace-level log

geckodriver.log.txt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions