SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.23k stars 8.11k forks source link

Selenium webdriver (2.52.0 and 2.53.0) are not performing a click on the webelement and passed the step without any error. #2030

Closed Kiran-CGI closed 7 years ago

Kiran-CGI commented 8 years ago

Meta -

OS:

Selenium Version:

Expected Behavior - The code is expected to click on payment templates and then click on load more link which appears in that page

@Test @Parameters({"browser", "userName", "password"}) public void loginWebFX(String browser, String userName, String password) throws Exception { String userNameTextBox = PropertiesFileReader.getPropertyValue("login.userName.textBox"); String passwordTextBox = PropertiesFileReader.getPropertyValue("login.password.textBox"); String menuIcon = PropertiesFileReader.getPropertyValue("home.page.menu.icon"); String paymentTemplates = PropertiesFileReader.getPropertyValue("home.page.menu.paymentTemplates"); String loadMore = PropertiesFileReader.getPropertyValue("paymentTemplates.loadMore"); String rowsPT = PropertiesFileReader.getPropertyValue("paymentTemplates.rows");

    DriverUtil.launchBrowserDriver(browser);
    DriverUtil.getUrl(PropertiesFileReader.getPropertyValue("webfx.login.url"));
    DriverUtil.enterText(userNameTextBox, userName);
    DriverUtil.enterText(passwordTextBox, password);
    DriverUtil.pressEnter(passwordTextBox);
    DriverUtil.click(menuIcon);
    log.debug(DriverUtil.findElement(paymentTemplates));
    Assert.assertTrue(DriverUtil.findElement(paymentTemplates).isDisplayed(),"PTs not displayed");

    DriverUtil.click(paymentTemplates);
    DriverUtil.waitforElementVisibility(loadMore, 20);
    log.debug(DriverUtil.findElement(loadMore));
    if (DriverUtil.findElement(loadMore) != null) {
        int intialPT = DriverUtil.findElements(rowsPT).size();
        log.debug("Initial rows are " + intialPT);
        String[] loadLinkText = DriverUtil.getElementText(loadMore).split(" ");
        int templatesToLoad = Integer.parseInt(loadLinkText[1]);
        log.debug("Payment templates to load " + templatesToLoad);
        DriverUtil.click(loadMore);
        int loadedPT = DriverUtil.findElements(rowsPT).size();
        Assert.assertTrue(intialPT + templatesToLoad == loadedPT,
                templatesToLoad + " are to be loadedd, but failed");
        log.debug("Payment templates after load " + loadedPT);

        DriverUtil.captureScreenshot("Loaded more");
        log.info("Load is tested");
    } else {
        log.info("Nothing to load");
    }

}

@AfterMethod
public void tearDown() {
    DriverUtil.closeBrowser();
    DriverUtil.shutDownDriver();
}

Actual Behavior -

But actually the selenium passes the click step without actually clicking on the payment templates link though it is available.

After searching for the solutions in google i doubt my maven dependencies are in compatable with latest selenium jar ie 2.52.0 or 2.53.0

'''--------pom.xml------------'''

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>com.maven</groupId>
<artifactId>com.maven.testng</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Maven-Testng setup</name>
<description>Maven-Testng setup</description>
<!-- Change from here -->

<packaging>jar</packaging>

<properties>
    <suiteXmlFile>testng.xml</suiteXmlFile>

</properties>

<dependencies> 

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
        <scope>test</scope>
    </dependency>

    <!-- Adding Selenium dependency -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.52.0</version>
    </dependency>

    <!--Group id and Version are referred from https://poi.apache.org/download.html, 
        Artifact id referred from https://poi.apache.org/overview.html -->

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.14-beta1</version>
    </dependency>
    <!-- For reporting -->
    <dependency>
        <groupId>org.uncommons</groupId>
        <artifactId>reportng</artifactId>
        <version>1.1.4</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>4.0</version>
        <scope>test</scope>
    </dependency>
org.apache.logging.log4j log4j-api 2.5 org.apache.logging.log4j log4j-core 2.5 com.microsoft.sqlserver sqljdbc41 4.1 runtime ``` org.apache.maven.plugins maven-compiler-plugin 3.5.1 1.7 1.7 org.apache.maven.plugins maven-surefire-plugin 2.19.1 usedefaultlisteners false listener org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter org.uncommons.reportng.velocity-log true target/ ${suiteXmlFile} ``` ''''------------------''' ''''-------testng.xml-----------''' ``` ``` ''''------------------''' At times i am getting staleElementReferenceException as well when trying to click the element, please provide me resolution for this problem. Thanks in advance.
spaceman27 commented 8 years ago

I am also having this issue in IE, it did not make actually click on web element, I am using selenium driver 2.53

ckorakidis commented 8 years ago

There's some issue with the focus in some cases. A workaround would be clicking first on the parent and then on the element if possible

acontell commented 8 years ago

I can reproduce this problem using Selenium 2.52 and ff 45.0.1.

@ckorakidis your workaround works like a charm, could you please give me more info about this issue so that I can investigate further? Our tests were working fine until last week so I don't know if it's something we introduced that is triggering the problem.

Thanks.

spaceman27 commented 8 years ago

selenium .click() in IE sometime work in weird way, it will wait forever until a new window is loaded. if we do not open a new window, we probably fall to this issue. Try javascript click instead ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].click()", Driver.FindElement(By.CssSelector("input .classname")));

Kiran-CGI commented 8 years ago

Dear all, In my case i ve found that element is not loading perfectly sometimes when the webdriver is trying to click.

  1. so Thread.sleep() for few seconds and then click() done the same task without fail. Even this failed sometimes. 2.Then instead of click() i imported Actions class and has done a mouseover and then click(). This didnot fail at all and the scripts are passing. 3.Downgrading the selenium jar may also solve the problem sometimes.
  2. @ckorakidis suggestion is worth trying.
  3. @spaceman27 work around is also a solution in think.

Thanks.

ckorakidis commented 8 years ago

Hi,

Apologies for not responding earlier, it was lost in my notifications.

So there are issues with click (in some cases it hangs, or it pretends it clicked when it didn't) on IE. To my experience no solution is perfect, a combination would reduce the failures though. The click on parent first was taken from http://stackoverflow.com/questions/5574802/selenium-2-0b3-ie-webdriver-click-not-firing. It's not panacea and in some cases, depending on your design, clicking on the parent could lead to having your element listening on the click event, so clicking on the parent and then on your element could lead to two clicks on your element. In some cases this could lead to weird behaviour (I had to realise it by analysing the network traffic). If you realise that this is the behaviour, I'd suggest you first click on some other place (of the same iFrame) you know it won't have any other effect except for the focus. The Keys.Enter didn't work as expected in my case: the click was successful but after that I had issues with the next commands (possibly related to focus or some other reason). The Actions approach seems to work in most of the cases: new Action(driver).moveToElement(myElement).click().perform(), so I use a combination of this and the first approach (click on parent or some other save-to-click place before clicking on myElement), depending on the interface. @acontell The click issues on IE are not constant and you could experience this even when you changed nothing. In general, to my experience, when the time management (loading of the page, or part of the page through some ajax, finishing of the previous action etc) in the front-end is not perfect, or the use of it is not perfect (e.g. not using waits where needed), you could face issues just because the server respond time changed for a small portion. If you run your tests in many iterations (e.g. using jmh), you'll realise that they fail more often than running them just once.

jimevans commented 7 years ago

No repro case, and no comments in 10 months. Closing.