0

I have a Selenium Java based automation infrastructure. Most elements locators are using XPath since our web site uses several templates where elements can be located based on their texts only.
It is working just perfect on Chrome however it doesn't work on Firefox.
The most basic action - element.click() doesn't work with Selenium on Firefox while it works perfect on Chrome!
There is no exceptions thrown, just nothing done.
I do not use any kind of very complex xPath expression, mostly something like //*[contains(text(),'Some unique text')] that gives a clear unique element locator and each click() is performed after getting the element visible with methods like this:

public void clickVisible(String xpath){
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
    driver.findElement(By.xpath(xpath)).click();
}

While running and debugging the tests I saw that elements are found visible shortly while running on Firefox too, however click() simply doesn't work there.
In case I locate those elements with css selector it works on Firefox perfect!
I already heard that xPath engines are different in each browser and I saw several old posts here dealing with xPath related problems, but mostly with IE, not with Firefox, and most of that posts are written many years ago.
Also, I worked with Firefox several years ago and there were no such problems that time!
I'm trying to understand what happened with Selenium on Firefox so it is not performing very basic commands for xPath located elements?
I couldn't find any clear documentation / explanation about this.
This post looks interesting, however I couldn't try setting capability.setCapability("marionette", false); since my Firefox options are set in the following manner:

FirefoxProfile profile = new FirefoxProfile();
FirefoxOptions options = new FirefoxOptions();
profile.setPreference("browser.download.dir",downloadsPath);
--------
options.setProfile(profile);
driver = new FirefoxDriver(options);
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Prophet
  • 32,350
  • 22
  • 54
  • 79

1 Answers1

3

Are you running the test in headless mode. If so you have to maximize the screen by setting it in environment variables.

 os.environ['MOZ_HEADLESS_WIDTH'] = '1920'
 os.environ['MOZ_HEADLESS_HEIGHT'] = '1080'

If not headless please update the firefox options to the below size to fix the issue.

firefoxOptions.AddArgument("--width=1920");
firefoxOptions.AddArgument("--height=1080"); 
  • Arjun
Arjun
  • 624
  • 2
  • 6
  • No, I'm currently trying to run in regular mode. – Prophet May 10 '21 at 16:41
  • then you can add the width and height in Firefox options and give a try – Arjun May 10 '21 at 17:18
  • I have tried that. unfortunately this didn't help. – Prophet May 10 '21 at 17:36
  • Please set the MOZ_HEADLESS_WIDTH and HEIGHT in system environment variable. Definitely its a size issue, most probably your buttons will be at the bottom of the screen. – Arjun May 10 '21 at 19:03
  • 1
    But why? I'm running NOT in headless mode. And It works perfect when I use css based selectors. The issue is definitely with `xpath` based selectors on FF – Prophet May 10 '21 at 19:06