Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't click an inline <a> that contains a block element #653

Open
juangj opened this issue Apr 18, 2017 · 11 comments
Open

Can't click an inline <a> that contains a block element #653

juangj opened this issue Apr 18, 2017 · 11 comments

Comments

@juangj
Copy link
Contributor

juangj commented Apr 18, 2017

Firefox Version

52.0 and 53.0b9 and 55.0a1

Platform

Linux (haven't tried others but it's probably the same)

Steps to reproduce -

This works with Chromedriver.

block.html

<!DOCTYPE html>
<html>
<body>
  <a href="http://www.example.com/">
    <div>Click me</div>
  </a>
</body>
</html>

block.py

import sys

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support import wait

caps = DesiredCapabilities().FIREFOX.copy()
caps['marionette'] = True
driver = webdriver.Remote(
    command_executor=sys.argv[1],
    desired_capabilities=caps)

try:
  driver.get('http://localhost/block.html')
  link = driver.find_element_by_css_selector('a')
  link.click()

  wait.WebDriverWait(driver, 3).until(
      expected_conditions.title_contains('Example Domain'))
  print 'ok'
finally:
  driver.quit()

Geckodriver log

geckodriver.log.txt

@juangj
Copy link
Contributor Author

juangj commented Apr 18, 2017

Clicking the <a> doesn't work, but asking WebDriver to click the <div> inside the <a> does work. The click also succeeds if the <a> has style="display: block".

This looks superficially similar to https://bugzilla.mozilla.org/show_bug.cgi?id=1307760, though the <img> in that case is an inline element. However, I can't reproduce the exact problem in that bug (an <img> inside an <a>) with the example attached to the bug, or with my own HTML.

@jochenberger
Copy link

Looks quite similar to #322

@njpearman
Copy link

I'm experiencing the same problem still with the following:

System

  • Version: 0.18.0
  • Platform: macOS 10.12.6
  • Firefox: 55.0.3
  • Selenium: Ruby 3.5.1

@snowymike
Copy link

snowymike commented Dec 21, 2017

any update on this one?

i experience the exact same problem as the submitter reported. clicking the anchor doesn't work, but clicking the child div works, and changing the anchor style to display: block also fixes it. the Exception i get is

org.openqa.selenium.ElementNotInteractableException: Element <a href="http://www.example.com/"> could not be scrolled into view

i'm using
Geckodriver 0.19.1 64-bit Windows
Windows 10
Firefox beta 58 64-bit
Selenium 3.5.3
Java

clicking this anchor works fine with chromedriver 2.33 and ie driver 3.0.0.0

@juangj
Copy link
Contributor Author

juangj commented Dec 21, 2017

(Disclaimer: I don't speak for Mozilla)

AFAIU, that is indeed the same problem, even though it's a different error message. The new WebDriver-compliant click code in FF58 produces that error instead of silently failing to click.

I haven't checked again, but IIRC what was happening with that anchor is that Firefox thinks it has multiple client rects, and the first client rect isn't what you'd expect:
{bottom: 12, height: 19, left: 8, right: 8, top: -7, width: 0, x: 8, y: -7}

The center point is (8, 2.5), which ends up being "above" the link that we're trying to click.

@snowymike
Copy link

thanks for the reply @juangj . have you come up with a workaround you're satisfied with, or are you waiting on a geckodriver or firefox fix? clicking the anchor through selenium works great in firefox 47.0.1 and the latest versions of chrome and ie (and of course works if i manually click in the browser with firefox 58, not using selenium). i'm reluctant to change all the html to use display: block for the anchor in such situations, for a variety of reasons (including my not having control over all the html). and i don't love the idea of clicking the child of the anchor when it's the anchor itself that has all the click handlers configured on it and should be the right thing to click.

anyone on the mozilla side have info on when/if we could expect a fix for this issue, either in geckodriver or a new version of firefox? looks like this has been broken for 8 months, just with varying errors (click does nothing now replaced with ElementNotInteractableException). i'm surprised this issue only has a few comments on it, as it broke the first test i tried to run with geckodriver. maybe this use of anchors and divs in this fashion isn't that common, or perhaps lots of people are still sticking with 47.0.1, as we will continue to be until we can get our tests passing using geckodriver.

thanks.

@juangj
Copy link
Contributor Author

juangj commented Dec 21, 2017

I'd suggest just clicking the child div, even though, as you say, it's more logical to be clicking the anchor. It's a little annoying once, but it's straightforward and is simple enough to undo after this gets fixed. I think that's better than changing the HTML under test solely to work around an automation bug -- the explanatory comment that you leave in the code about this will make more sense if it's written in your test code rather than in your HTML templates.

This bug affects a relatively small fraction of tests in my codebase, but of course everybody's experience will vary, depending on the thing that you're testing.

@Me-ion
Copy link

Me-ion commented Apr 11, 2018

Any updates on this? Still an issue with geckodriver 20.1 and FF 59. In my case, I have a dropdown with only anchor elements. They have no child elements I could use to click on, so this issue is a complete blocker for me. Works fine with chromedriver

@slaout
Copy link

slaout commented Aug 9, 2018

Any news on it?

We have the problem with this sort of HTML:

<a ... style="display: table-footer-group; width: 100%;">
    <div>...</div>
</a>

@andrewnicols
Copy link

Just to confirm that this is still a bug in Geckodriver 0.26.0.

Is there any news on the resolution of this issue, is there anything that can be done to help with its resolution?

@whimboo
Copy link
Collaborator

whimboo commented Dec 23, 2019

Please note that work related to this problem is tracked on https://bugzilla.mozilla.org/show_bug.cgi?id=1374283. Sadly we don't have an ETA right now. Sorry.

andrewnicols added a commit to andrewnicols/moodle that referenced this issue Jul 2, 2020
There is a bug in Geckodriver which means that it is unable to click any link which contains a block
level node. See mozilla/geckodriver#653.
The workaround is to click on it's first descendant instead.
andrewnicols added a commit to andrewnicols/moodle that referenced this issue Nov 17, 2020
There is a bug in Geckodriver which means that it is unable to click any link which contains a block
level node. See mozilla/geckodriver#653.
The workaround is to click on it's first descendant instead.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 4, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 4, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 6, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 7, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 7, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 7, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
andrewnicols added a commit to andrewnicols/moodle-behat-extension that referenced this issue Dec 7, 2020
There is a bug in Geckodriver which means that it is unable to click any
link which contains a block level node.

See mozilla/geckodriver#653.

The workaround is to click on it's first descendant instead.

This is achieved thorugh finding it's first child and clicking that
instead.

Note: This is not a perfect workaround as the first child element may
not be the one containing the block element, but normally this situation
only occurs where the only immediate child is a block element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants