Selenium webdriver (2.52.0 and 2.53.0) are not performing a click on the webelement and passed the step without any error.
See original GitHub issueMeta -
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"> <modelVersion>4.0.0</modelVersion> <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>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,
org.uncommons.reportng.JUnitXMLReporter</value>
</property>
<property>
<name>org.uncommons.reportng.velocity-log</name>
<value>true</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
‘’‘’------------------‘’’ ‘’‘’-------testng.xml-----------‘’’
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Web FX Sprint 1 User Stories"><test name="Firefox Test">
<parameter name="browser" value="Firefox" />
<parameter name="userName" value="kiranp" />
<parameter name="password" value="9133222151" />
<classes>
<class name="com.cgi.webfx.testscripts.LoginTest" />
</classes>
</test>
<test name="Internet Explorer Test">
<parameter name="browser" value="IE" />
<parameter name="userName" value="kiranp" />
<parameter name="password" value="9133222151" />
<classes>
<class name="com.cgi.webfx.testscripts.LoginTest" />
</classes>
</test>
<test name="Chrome Test">
<parameter name="browser" value="chrome" />
<parameter name="userName" value="kiranp" />
<parameter name="password" value="9133222151" />
<classes>
<class name="com.cgi.webfx.testscripts.LoginTest" />
</classes>
</test>
</suite>
''''------------------'''
At times i am getting staleElementReferenceException as well when trying to click the element, please provide me resolution for this problem.
Thanks in advance.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
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.
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”)));