7

Since I upgraded to the newest Selenium version my Firefox driver is not working properly. Failing to find an answer from searching Google/Stack I hope someone here has an answer.

I've build a page object model for logging in to a webpage, clicking the admin-site and filling in username/password + submitting. This code was written for Selenium 2.53.6 but still works for IE and Chrome. The part that is failing for me is this line of code:

driver.find_element_by_xpath(locators["login.open"]).click()

The locator is:

locators["login.open"] = "//*[@href='//www.phptravels.net/admin']"

Since it is working in IE and Chrome then it puzzles me that Firefox can not .click() anymore?

I'm not getting an error message in my console, it just doesn't click the admin-site button. Could this be related to a given Firefox version for Selenium 3/geckodriver?

All drivers are up to date using pip

I am using this site for practicing my Selenium: http://phptravels.com/demo/

Edit (1): I've tried with Firefox version 48 and 49 - still not working

Edit (2): geckodriver is configured with Firefox binaries declared however the driver is still not performing the .click()

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)

Edit (3): I check if the element is present by the xpath locator using is_displayed() and it returns True. So I know that it can find the element.

Edit (4): 1) Tried with the Nightly build as suggested, not working. 2) Tried with find_element_by_link_text, also not working. 3) Tried various versions of geckodriver (10.0, 11.0, 11.1 for 32 and 64 bit on all versions)

Edit (5): "Plugin Container for Firefox has stopped working" spawns consistently every time a test case fails.

Edit (6): Possible solution to the problem: I did another test on a different website, and Firefox successfully performs a .click(). On the first target webpage where .click() fails is a huge javascript that runs when you open the page. This could possibly mess up with the geckodriver's ability to do .click() on javascript-heavy pages.

Edit (7): Using .send_keys(Keys.RETURN) with the Keys library works, but might require additional reconfiguration if you're using POM. Explicitly doing some time.sleep will get you around, but for now it's still brittle to use Selenium 3 + Firefox/geckodriver for web browser automation. Downgrade to last stable version (2.53.6) if you need to test Firefox (note: newest versions of Firefox wont work).

MSJ
  • 154
  • 1
  • 3
  • 10
  • 2
    I am having the same problem (but using Java). I have run into several issues like this with the geckodriver since upgrading to v3. It seems like some links can be clicked in this way, while others refuse to be clicked. I have had some success using xpath such as //a[text()='linktext'] instead of By.linkText, but it's not consistent. There is no API way to know if a click succeeded or not. – Alice Young Oct 21 '16 at 13:31
  • I am seeing this problem too (in C#) after upgrade to selenium 3. – LayerCake Oct 31 '16 at 08:18
  • RE: Edit #6. What happens if you perform a Thread.Sleep(10000) before the click, to let the page settle down or whatever. Just as a troubleshooting measure... – redwards510 Nov 07 '16 at 21:29
  • 1
    I've tried that but didn't work. But thanks for the suggestion. Sometimes that actually helps, but not in this case. I have also an implicit wait for all elements as well and I try to refrain from having explicit waits since that would slow down my test more than it has to – MSJ Nov 08 '16 at 07:53
  • I have the same bug, while using Python 2.7 with Selenium 3.0.2 and gecko driver 0.11 and Firefox Developer Edition 52.0a2. My walk around: https://gist.github.com/mpasternak/f2840edea51c211d609daa7f17be614f . I call jQuery to click the item, this way it does not have to be scrolled into view and then I ignore some kind of marionette bug, where it tries to get the return value from the javascript. Actually, previous Firefoxes hang when my Selenium library (Splinter) tries to open "about:blank" URL so... – dotz Dec 21 '16 at 23:21

5 Answers5

3

I'm having same issue, but sometimes .click works and other times it does not. It's not handling switching to newly opened windows well for me and a few other quirks causing tests that passed in Selenium 2.53.4 and that pass with Selenium 3 in Chrome, Safari & IE to fail in FireFox. I know this isn't very specific, but I've already posted looking specific questions elsewhere.

I'm using Ruby/Selenium/Capaybara. After extensive testing with the Selenium 3/Geckodriver/FF49 combo, I reverted to Selenium 2.53.4/FF47.01. My impression was that Selenium 3/Geckodriver combo is not quite stable yet, which may or may not include Capybara's compatibility with Geckodriver. I'd love to be wrong. I've scoured the internet for any helpful info and haven't found it.

I did, however, find this note from Selenium 3's release blog announcement: "Mozilla has been a front-runner in implementing the W3C WebDriver protocol. On the plus side, this has exposed problems with the spec as it has evolved, but it also means that Firefox support is hard to track as their engineering efforts have been forward looking, rather than on supporting the current wire protocol used by Selenium WebDriver. For now, the best advice we can offer is for you to try the latest release of geckodriver and Selenium together."

3

Can be this bug?

After a week I disable marionette (java):

capability.setCapability("marionette", false);

It's repair everything. Don't ask me why.

answer42
  • 65
  • 5
  • That bug is made by me :-). I've moved on long time ago. if someone can confirm that disabling marionette works then I'll approve your answer. – MSJ Jun 13 '17 at 11:55
1

I was using v0.11.1 of GeckoDriver and v3.0 of Selenium and had the same problem. My workaround was to pass a By.XPath instead of By.LinkText to FindElement. As OP mentioned, I was getting "true" returned when finding the element, it just wouldn't process the click on it for some reason.

 driver.FindElement(By.XPath("//something")).Click();
redwards510
  • 1,802
  • 1
  • 17
  • 23
  • I'm using Xpath as well and in the same way as you. Weird it isn't working. Are you running the 32 or 64 bit geckodriver? – MSJ Nov 07 '16 at 07:32
  • @MSJ 64-bit sir – redwards510 Nov 07 '16 at 21:23
  • That's the same for me. However, it seems as per Edit (6) that geckodriver can't handle some pages with specific kind of javascript. On the webpage that i test there is a pop-up chat feature in the bottom right. I suspect that it messing with the geckodriver – MSJ Nov 08 '16 at 07:57
  • @MSJ Interesting theory. On our pages we have a third party js overlay widget called WalkMe.js. I figured out how to destroy and remove it from the DOM with a single specific line of javascript using the JavascriptExecutor. Perhaps that is why it works for me? Try contacting the chat widget authors to see if there is a kill command for it. – redwards510 Nov 08 '16 at 17:58
  • 1
    I want to add that I have a similar ".Click() is broken" issue and I filed a bug report for it.. https://github.com/mozilla/geckodriver/issues/324 – redwards510 Nov 08 '16 at 18:00
1

I am also Facing the same issue with selenium 3 FF, but Able to run with JS executor and Keys.RETURN or Keys.ENTER

With JS Executor :

WebElement button = driver.findElement(By.cssSelector("input[value=btn]"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", button);

With Keys.RETURN or Keys.ENTER:

driver.findElement(By.id("abc")).sendKeys(Keys.RETURN);
driver.findElement(By.id("abc")).sendKeys(Keys.ENTER);
demouser123
  • 4,108
  • 9
  • 50
  • 82
  • This is the only solution that worked for me! My button is inside an iFrame, and I tried selenium 3 and 4 but nothing has worked out. For some reason, chrome was working without any problem, but firefox doesn't perform the click no matter what, this javaScriptExecutor was the only solution for it! – n0krashy Apr 04 '23 at 18:29
0

I'm having the same issues right now, I tried using the nightly build and it started working though I am having issues with it trying to click things before they are ready but that's more my issue than Selenium itself.

Current nightly build version is 52.0a1, you can find it here.

By default the FirefoxDriver will still use your regular install of Firefox, so you'll need to create the Driver using a profile/options/binary, I do it like so (in C# but should be pretty similar in Python);

var binary = new FirefoxBinary(@"C:\Program Files (x86)\Nightly\firefox.exe"); Driver = new FirefoxDriver(binary, null);

I think it might be FirefoxDriver(binary: binary)in Python but not completely sure. Note that using FirefoxBinary is obselete as of Selenium 3 in favor of FirefoxOptions but it'll let you test if that's your issue for the time being.

Dillanm
  • 876
  • 12
  • 28
  • 1
    Hi Dillanm. Than you for your reply. I have declared the Firefox binary in my code (as per Edit (2)). I have updated with a code example. Still not working though. I'm waiting for an update for geckdo/marionette as I think that might solve the problem – MSJ Oct 27 '16 at 08:33
  • Did you try it with the nightly build though? @user2782743 – Dillanm Nov 01 '16 at 16:29
  • 1
    I've just tried with the nightly build. I've declared the binaries to the nightly build but it's still the same. It doesn't click. I've even tried to locate something else than what Chrome and IE locates, but still not .click'ing – MSJ Nov 02 '16 at 12:09