0

I'm working on a Product automation(Web CMS), where element.Click() shows the inconsistent behaviour. Basically we are using,

Selenium + Nunit GUI(unit testing framework) - To run the test cases from local on a particular environment
Selenium + Asp.net web application - Multiple user's can run the test cases on different environment
Here environment I mean different levels(Dev, SIT, QA, Production).

My Concern
In one of my test cases, I want to Click a button. So for that, I have tried few code. But all are inconsistent behaviour. Here Inconsistent I mean, the code whatever I wrote for clicking a button are only working in my local or server and viceversa.

1st attempt:-
I tried all the element locator's

IWebElement element = driver.FindElement(By.Id("element id goes here"))

Working fine at my local, but not in server
Result - Failed

2nd attempt:-

driver.FindElement(By.XPath("Element XPath goes here")).SendKeys(Keys.Enter);

Working fine at server, but not in local
Result - Failed

3rd attempt:-

 IWebElement element = driver.findElement(By.id("something"));
    IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
                        executor.ExecuteScript("arguments[0].click()", element);


Not working in both(local and server)
Result - Failed

At last, I tried waiting for the element to be visible and performing action

4th attempt:-

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
                return wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("element xpath goes here")));<br>

After webdriver wait performing action on that element (element.click())
Working fine at local but not in server
Result - Failed

I'm looking for a solution, where Clicking the button should not be an inconsistent behaviour. Basically it should work fine in both (Local and Server). Your help would be greatly appreciated..Thanks in advance
FYI - I'm testing in Mozilla Firefox browser 38.5.2

  • What was the output/error message in the failure cases? – ernie Feb 20 '16 at 0:42
  • @ernie - basically it is opening a pop-up blocker window at the browser when clicking that button, so it couldn't proceed further – Aishu Feb 20 '16 at 10:15
  • When I use sendkeys(keys.Enter) at my local I'm getting that pop-up blocker window, but it is working fine in server – Aishu Feb 20 '16 at 10:18
1

It is better to use ids than XPath because XPath changes as elements are moved around the page, making your tests more fragile.

Can you see what the server is actually doing? Are you on the page you think you are or is it redirecting you?

I have had failures when clicking elements that had other elements overlapping them, I had to scroll the page slightly to fix it.

Can you use a different browser altogether?

0

Keep in mind that the events element.sendKeys, driver.navigate.to and element.click are native events for the browser. For them to succeed, they need to talk successfully to whatever version of the browser you have on your system. In nearly all cases, this works, but sometimes, such as with all versions of Firefox after 31.6.0, the compatibility with Selenium has degraded and you'll get wierd behaviour that you can't explain. There is no need to fret. In your test framework you can create a JavascriptExecutor method that does the same thing non-native. As a workaround, that should work for you, but fundamentally you shouldn't need to do that if you match up the Selenium version with the right versions of the binary browser.

So, your solution: on the server, downgrade Firefox to version 31.6.0 ESR, which is difficult because Firefox tries to upgrade itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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