Selenium 2.48.1 Firefox clicking wrong element as page loads
Environment: C#, Nuget Package Selenium 2.48.1, Firefox
In firefox Selenium is clicking the wrong element in firefox in very specific situations,
For example... Load New page via URL Run Method that waits until an element is displayed (pulls every half second to see if it returns Displayed as true) and then clicks that element. Element needs to be scrolled down to for it to be clicked Browser does not scroll and another element that navigates me to another page is clicked in its place (xpath is not the problem i'm using a unique ID)
The other element being clicked does not cover the desired element, it's actually no where near it. If i debug the test and step through it (slow it down) it clicks the correct element and the test passes so it must be some sort of race condition.
My thought is that the problem occurs when i try to click the element right as it returns displayed as true when the page loads and it has to scroll down to get it. That seems to be the only place i'm running into this issue at.
Also worth nothing that this test passes fine in 2.47
Can you share your test case?
Can do, there is a lot of stuff done in the wrapper I wrote for selenium but I'll try to have it make sense.
LoginHelper.Login(Sites.Masada, user);
FW.LogInfo("Attempting to Accept deal " + deal.Id);
//Navigate to page
EditDealPageBase.CoordinatorLoadDealByGuid(deal.DealGuid.ToString());
//This is the button i'm trying to click, with the click validation passed in as a param
EditDealPageBase.BtnScheduleStart.Click(EditDealPageBase.TxtAddNewTag.IsDisplayed);
//For reference here is how i find the BtnScheduleStart Element
public static Element BtnScheduleStart { get { return Browser.FindElement("scheduleStartDateButton", FindTypes.Id); } }
//Here is my custom click method, it tries to find the element, if it's not there it waits and tries to find the element again
for (int i = 0; i < RetryCount; i++)
{
try
{
if (WebElement.Displayed)
{
LogAction("Click", i + 1);
break;
}
}
catch (Exception)
{
}
Thread.Sleep(1000);
if (failMessage != null && i == RetryCount )
{
FW.AssertFail(failMessage);
}
if(failMessage == null && i == RetryCount)
{
LogElementNotFoundFailure();
}
WebElement = Browser.FindElement(Query, Type).WebElement;
}
try
{
Browser.Highlight(this);
WebElement.Click();
}
catch (Exception e)
{
FW.LogInfo(e.Message);
}
}
Here is what the page looks like before the click is attempted, the button i want to click is slightly out of view below.

Here is the page expanded with the button i want to click at the bottom, and the button that is being clicked at the top (I know it's getting clicked because the test fails on the page that top link leads to)

It's worth noting that there are two ways I can make this test pass, if i slow the test down and step through it all it passes fine, also if i maximize the browser so that the button I'm trying to click is in view right when the page loads it also clicks the correct button. Or if i downgrade to 2.47.0.
But on 2.48.1 it fails every time because it navigates away from the page i'm still trying to do work on and goes to the page that top button links to.
I write pretty much any exceptions thrown to the test log and i'm not seeing any weird exceptions on that click either.
+1 as we seem to hit the same problem
@davehunt I've sent a link to gist with a test to @barancev via email, because it runs on our production website and uses credentials of one of our test users. Please let me know if I should send it to you as well.
Originally I wanted to reproduce issue #1420, but it looks like it actually reproduces this one. In my test I'm waiting for 5 seconds for page to fully load, but it still doesn't click correct element. Works fine with webdriver 2.47.0.
Please retest with 2.49, autoscrolling should be fixed in this release.
I see the same problem (clicks happening to wrong element). My understanding is that selenium implements clicks based on where the element is when the click is called, but if the element moves between the time the click is called and when the event gets sent to the browser, it will click on whatever is under that original location, whatever it is. barancev suggests upgrading to 2.49, but I'm running nightwatchjs in javascript, which is currently at 2.48.2. Is there a new version that solves this problem for javascript?
Assuming it's fixed