Skip to content

.click broken for Selenium 3 #322

Closed
Closed

Description

@MartinSoeesJohansen

As with Selenium 3 and the need of geckodriver for web browser testing the .click() is broken.
Environment:
Windows 7
Firefox 49.0.2
GeckoDriver 11.1-64bit
Selenium 3.0.1
Python 3.5.2

Elements can be found by Selenium either by xpath, css or link text, but .click() is not performed.
Please see the Stack link for a detailed explanation of what I've done so far.

EDIT: it seems to be working on pages without heavy javascript source code. So it might be geckodrivers ability to handle javascript??
This page works: www.dr.dk
This page doesn't work: www.phptravels.com/demo

A longer, thorough, explanation can be found on Stack here

Activity

  1. AutomatedTester commented on Nov 11, 2016

    @AutomatedTester
    Contributor

    I was able to reproduce. However, hitting return on the element works

    from selenium import webdriver
    f=webdriver.Firefox()
    h=f.find_element_by_xpath("//a[@href='/p/https://github.com/p/https://www.phptravels.net/admin']")
    h.click()
    from selenium.webdriver.common.keys import Keys
    h.send_keys(Keys.RETURN)
    
  2. MartinSoeesJohansen commented on Nov 11, 2016

    @MartinSoeesJohansen
    Author

    Great that Keys.RETURN works, thank you.
    I'll try and implement that, but shouldn't it still be possible to use .click? It sucks to be having to write hacks for Firefox because geckodriver doesn't work properly.

  3. andreastt commented on Nov 14, 2016

    @andreastt
    Contributor

    @AutomatedTester Do you have an idea what’s wrong here so we can file a Marionette bug?

  4. AutomatedTester commented on Nov 14, 2016

    @AutomatedTester
    Contributor

    I havent looked into the html, but feels like there might be something is catching the click that shouldnt be or something like that

  5. danhumphrey commented on Nov 15, 2016

    @danhumphrey

    I have experienced a number of issues where GeckoDriver and Selenium 3 clicks are broken when they are working in other browsers, however, I don't have a public reproducible test case :(

    In my case, I have clicks which:

    • Work in all browsers (including Firefox) using Selenium 2.53.1
    • Work in Chrome and Edge using Selenium 3.0.1

    but do not work with GeckoDriver 0.11.1 with FF Nightly or FF 49.0.2

    In my case the element is found and there are no exceptions thrown - the click simply has no effect.

    I'm attempting to find a public demonstration of this, which led me to this issue, however, in this instance, I am getting an ElementNotVisibleException with the following code:

    driver.get("http://phptravels.com/demo.php/");
    WebElement element = driver.findElement(By.xpath("//a[@href='/p/https://github.com/p/https://www.phptravels.net/admin']"));
    
    //I thought moveToElement might help but this doesn't appear to be implemented in GeckoDriver yet 
    
    //Actions actions = new Actions(driver);
    //actions.moveToElement(element);
    //actions.click();
    //actions.perform();
    
    element.click();
  6. demisk commented on Nov 15, 2016

    @demisk

    The problem I'm seeing is with clicking on text fields. Calling element.click() changes the current active element (document.activeElement), but it seems that focus events are not firing.

    For example, given the URL [http://phoenix.pslc.cs.cmu.edu/QA/Tutors_trunk/html5_interfaces/fractionAddition.html?tutoring_service_communication=javascript&question_file=http://phoenix.pslc.cs.cmu.edu/QA/Tutors_trunk/html5_brds/FractionAddition/1213.brd],

    the following code worked in Selenium 2, but it does not work in Selenium 3 with the gecko driver (i.e., the text in e1 does not turn green):

    WebElement e1 = driver.findElement(By.id("ctatdiv26"));
    e1.click();
    e1.sendKeys("6");
    WebElement e2 = driver.findElement(By.id("ctatdiv32"));
    e2.click();
    // assert text in e1 is green
    
  7. aviita commented on Nov 23, 2016

    @aviita

    I am using C# for programming Selenium tests.

    For me the following code works (so without gecko driver?):

    FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
    service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
    IWebDriver driver = new FirefoxDriver(service);
    

    And this does not work (with gecko driver):

    IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox(), TimeSpan.FromMinutes(10));
    

    I have 64 bit version of gecko driver (geckodriver-v0.11.1-win64) and the gecko driver seems to be launching 32 bit version of firefox. The test works up until the first Click event.

    I can see that there is this stange opacity on the page where the click does not work. Additionally the click does not work even when continuing to to use the browser with mouse like you normally would. If I hit return on the page, I get to the next page and the opacity disappears. On the second page the click once again operates normally when used with a mouse.

    If I add the SendKey, the rest of the test goes through just fine:
    driver.FindElement(By.ClassName("js-newdesign-wizard-next")).SendKeys(Keys.Return);

  8. AutomatedTester commented on Nov 23, 2016

    @AutomatedTester
    Contributor

    If anyone can help reduce the HTML needed to get this issue fixed that would help us fix it quickly.

  9. jsaltz commented on Nov 28, 2016

    @jsaltz

    This code works for Chrome:
    actions.MoveToElement(element).Perform();
    Browser.Instance.FindElements(click).FirstOrDefault()?.Click();

    But results in this error for Gecko:
    An exception of type 'System.NotImplementedException' occurred in WebDriver.dll but was not handled in user code
    Additional information: POST /session/c66773d7-38a6-4616-b771-e605b9c201c4/moveto did not match a known command

    I've not yet found a workaround to implement a click on an anchor link.
    Trying to bypass MoveToElement and Click() with SendKeys -
    Browser.Instance.FindElements(click).FirstOrDefault().SendKeys(Keys.Return);
    --just ends up throwing this: An exception of type 'OpenQA.Selenium.ElementNotVisibleException' occurred in WebDriver.dll but was not handled in user code

    It's the MoveToElement that's broken in this driver. Any ETA for a fix to this?

  10. danhumphrey commented on Nov 28, 2016

    @danhumphrey

    @jsaltz the NotImplementedException means literally that - Actions are not yet implemented in geckodriver. This issue is highlighting a problem where an element is found (is visible and clickable), but the click method has no effect and no Exceptions are thrown.

  11. jsaltz commented on Nov 28, 2016

    @jsaltz

    I got a jquery workaround for this.
    In a block after determining the browser is Firefox I have:
    IJavaScriptExecutor js = Browser.Instance as IJavaScriptExecutor;
    //NOTE: Browser.Instance is my IWebDriver = new FirefoxDriver()
    var TheAnchorTag = Browser.Instance.FindElements(TheAnchorTagYouWantToClick).FirstOrDefault();
    string jsScript = "$( document ).ready(function() { " +
    "window.location.href = $("a:contains('" + TheAnchorTag.Text + "'):last").attr("href");" +
    "});";
    js.ExecuteScript(jsScript);

    Fun at the old Firefox ballpark

  12. caladd commented on Dec 7, 2016

    @caladd

    Here is a crude workaround for the click not pausing long enough for the page to fully load:

    from time import sleep
    from selenium import webdriver
    from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener
    
    class EventListener(AbstractEventListener):
        def after_click(self, element, driver):
            sleep(1)
    
    driver = EventFiringWebDriver(webdriver.Firefox(), EventListener())
    
  13. heyrex commented on Dec 13, 2016

    @heyrex

    I can confirm many, many troubles sending clicks. It's particularly bad with radio buttons and checkboxes but has also manifested on list items, hrefs and input type=submit.

    In some cases I've been able to work around by scrolling the item further into the viewport using a window.scrollTo() or window.scrollBy() JS call. Other times I'm just completely stuck and have to send key presses instead.

    I've noticed that at certain times of day I can click something and at other times (randomly) I cannot. Our entire collection of test suites passes flawlessly against Chrome.

    Firefox: 50.0.2
    Geckodriver: 0.11.1
    Selenium: 3.0.1
    Windows 7 64 bit

  14. dylanlive commented on Jan 12, 2017

    @dylanlive

    I'm replicating this issue as well. It seems geckodriver can't click game elements (.game-item) from www.twitch.tv/directory

    Specs:
    Firefox: 50.1.0
    Geckodriver: 0.13.0
    Selenium: 3.0.5
    OS: macOS 10.12.2

    Example in Capybara:

    visit 'https://twitch.tv/directory'
    first('.game-item').click
    

    geckodriver Debug Logs:

    -> POST session/887dc33d-302a-eb46-ac1c-f2c0fa3b2573/element/6c9c7ca7-a9ec-f14f-af4e-2091187fb62d/click
    1484251211336	hyper::server	DEBUG	Incoming stream
    1484251211336	hyper::server::request	DEBUG	Request Line: Post AbsolutePath("/session/887dc33d-302a-eb46-ac1c-f2c0fa3b2573/element/6c9c7ca7-a9ec-f14f-af4e-2091187fb62d/click") Http11
    1484251211336	hyper::server::request	DEBUG	Headers { Accept: application/json, Content-Length: 2, Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3, User-Agent: Ruby, Connection: close, Host: 127.0.0.1:4444, Content-Type: application/x-www-form-urlencoded, }
    1484251211337	webdriver::server	DEBUG	Got request POST AbsolutePath("/session/887dc33d-302a-eb46-ac1c-f2c0fa3b2573/element/6c9c7ca7-a9ec-f14f-af4e-2091187fb62d/click")
    1484251211337	webdriver::command	DEBUG	Got request body {}
    1484251211337	geckodriver::marionette	DEBUG	→ 66:[0,8,"clickElement",{"id":"6c9c7ca7-a9ec-f14f-af4e-2091187fb62d"}]
    1484251211365	geckodriver::marionette	DEBUG	← [1,8,null,{}]
    1484251211365	webdriver::server	DEBUG	Returning status Ok
    1484251211365	webdriver::server	DEBUG	Returning body {}
    1484251211365	hyper::server::response	DEBUG	writing head: Http11 Ok
    1484251211365	hyper::server::response	DEBUG	headers [
    Headers { Connection: close, Content-Type: application/json, Content-Length: 2, Date: Thu, 12 Jan 2017 20:00:11 GMT, }]
    1484251211365	hyper::server::response	DEBUG	write 2 bytes
    1484251211365	hyper::server	DEBUG	keep_alive = false for 127.0.0.1:50500
    1484251211365	hyper::server	DEBUG	keep_alive loop ending for 127.0.0.1:50500
    <- {}
    

    I've also done typical debugging such as adding sleeps, etc. An element gets returned upon clicking, but the click doesn't go through.

    As described above, sending the enter key works.

    visit 'https://twitch.tv/directory'
    top_game = first('.game-item')
    
    top_game.click
    top_game.send_keys(:enter)
    
  15. 37 remaining items

  16. whimboo commented on Sep 27, 2017

    @whimboo
    Collaborator

    @JamiePendleton without a trace log and even better a HTML snippet to reproduce it we cannot help. So if you have one which permanently reproduces the problem please provide it to us. This would be totally helpful. Thanks.

  17. JamiePendleton commented on Sep 27, 2017

    @JamiePendleton

    I'll post more soon if need be, for now however on sauce labs, the same tests that were failing at click now work. I am not sure how yet, but the tests passed. I'll need to see if I can get a repro.

  18. jpatel13 commented on Sep 28, 2017

    @jpatel13

    I'm encountering the same issue( have to call click twice) for element to be clicked.
    Details:
    gecko-driver-0.19.0 x64 windows 10 Firefox 56
    selenium-server-standalone 3.5.3
    Calendar snippet.txt
    testfunc.txt
    Let me know if you need more info.
    Thanks!

  19. JamiePendleton commented on Oct 1, 2017

    @JamiePendleton

    Its working for us now but was failing clicking the second link in our nav bar . Here is the element

  20. automationgeeks commented on Oct 4, 2017

    @automationgeeks

    I am also facing same problem with Geckodriver. Click events are not working, However working fine for chrome and older versions of firefox.

    is Geckodriver not stable yet to make a switch from Selenium 2.0 to 3.0? Or am I doing anything wrong with its integration.

  21. whimboo commented on Oct 4, 2017

    @whimboo
    Collaborator

    @automationgeeks, we cannot guess. You haven't given any details about your issue, and at least a trace log would be very helpful.

    @jpatel13 thank you for the testcase, but the test doesn't match with the HTML you have provided. Please make sure to fix it. Otherwise it's not that clear what to run. Thanks.

  22. andresmauriciogomezr commented on Nov 28, 2017

    @andresmauriciogomezr

    I got the a similar trouble,

    after a click event, a div is hidden and another div gets visible, the second div contains some elements including checkboxes and a button, when i try to click one of these elements i get a ElementNotInteractableException in FireFox, but works well on Chorme and IE

    i've tried with many wait methods and can't get it working

  23. andreastt commented on Dec 16, 2017

    @andreastt
    Contributor

    @andresmauriciogomezr I would file a separate issue instead of hijacking this, but it sounds like that is a result of the newer and stricter element interaction rules in WebDriver that aren’t implemented in Chrome and IE yet. See https://www.hskupin.info/2017/12/15/element-interactability-checks-with-geckodriver-and-firefox-58/ for more details.

  24. andreastt commented on Jan 9, 2018

    @andreastt
    Contributor

    I’m going to go ahead and close this issue because it doesn’t have a concrete description of the problem or a trace log we can use to debug it. The test case that was originally quoted can’t be reproduced in recent Firefox versions.

    I should also add that we have made a series of large changes to how element clicking works to align geckodriver closer to the WebDriver standard. Some of these changes may affect your tests, so if you have concrete concerns about how it works it will be better to file new issues on those.

  25. elliterate commented on Jan 9, 2018

    @elliterate

    @andreastt I have a failing test case and trace log in #1007, which was closed as being a duplicate of this. Can that one be reopened?

  26. andreastt commented on Jan 9, 2018

    @andreastt
    Contributor
  27. lock commented on Aug 16, 2019

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.

  28. locked and limited conversation to collaborators on Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址