3

I will try to be as clear as possible. Lets take an identical test case in both browsers. Open a page and find an element by the following method:

wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Logout"))).click(); 

Absolutely identical cases and it works fine in Chrome but in Firefox it doesn't find the element. I'm using:

Selenium 3.4
GeckoDriver 0.16 
Firefox 53.0

P.S After sometime i found out that the only difference is that thous elements that are located in and which i want to find by text aren't reachable. Even though it works perfectly with Chrome. Is there any way to deal with this or i have to make a totally new class and take another approach?

1
  • You can do this using native javascript, using the execute script in Selenium Apr 30, 2017 at 17:54

3 Answers 3

1

Most reliable way to locate element is by ID or name, or possibly CSS locator. Locating using other element attributes is less reliable.

Least reliable is the one method you can find most often in questions (so you can guess that is most error-prone) - by XPath.

Think how this functionality is implemented. WebDriver implementation has to have a own mirror copy of browser's DOM, and manipulate own copy to keep it in sync with the browser's copy. And both versions will use caching and other optimizations for performance. Many things can go wrong in such situation, it is amazing it is working as reliably as it is.

0

You will find this a lot between different browsers.
Investigate with manual delays and simple find element to start narrowing down the problem.
You may need to adjust the test code in order for it to be passable in different browsers.

1
  • This is a good and reasonable answer i agree but still, in basic theory it can't click nor find an element despite the fact that it is clickable, does it mean there is a problem with the GeckoDriver? I even used the following method: presenceOfElementLocated before waiting for it to be clickable and still no result.
    – R.Ro
    Apr 30, 2017 at 12:38
0

The issue you were facing might be due to the differences in the way each browser handles web elements. Some elements may be rendered differently in different browsers, causing the same code to work in one browser but not in another.

One approach to resolve this issue is to use more robust locators that are less dependent on the actual rendering of the web page. For example, instead of using By.linkText("Logout"), you could use By.xpath("//a[contains(text(),'Logout')]"). This xpath locator finds all <a> elements that contain the text "Logout".

Another thing to try is to update your Selenium and GeckoDriver versions to the latest stable releases. This might resolve any compatibility issues that are causing the element not to be found in Firefox.

It's also worth checking if there are any browser-specific configurations that need to be set in order for the test to run properly. For example, Firefox may require a different profile to be used, or certain browser settings may need to be adjusted.

If none of these approaches work, you may need to create a separate class for Firefox and modify the test case accordingly. However, this should be a last resort as it can add additional maintenance overhead and increase the complexity of the test suite.

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.