Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 3 Firefox .click() not working

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).

like image 397
MSJ Avatar asked Oct 17 '16 06:10

MSJ


2 Answers

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."

like image 55
user2690962 Avatar answered Dec 22 '22 20:12

user2690962


Can be this bug?

After a week I disable marionette (java):

capability.setCapability("marionette", false);

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

like image 27
answer42 Avatar answered Dec 22 '22 18:12

answer42