If anyone knows what is going on here, I would really appreciate it. I have spent hours trying to understand why an update button on a password change page sometimes gets activated and other times not. The scenario where the update button gets clicked to make the password change happens when the test executes quickly enough. If I run the same test on a slower machine, then the test will fail to click the update button periodically. There are no errors thrown by Selenium, I see the update button being clicked by the test, but the actual update to the password doesn't happen and then my test fails. I am clicking on this button in the below code...
<input type="button" name="Execute" value="Update" onclick="javascript:setTheState(this);" class="menuButton" data-hasqtip="8" oldtitle="Update" title="" aria-describedby="qtip-8">
I have tried all of these suggestions to get the Update button clicked consistently, even if the test runs more slowly on a slower system. All of my attempts result in the same problem. On the slower system, I see the Upadte button being clicked, no errors but the password is not reset and then my test fails.
1) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
sleepTheThread(10000);
updateBtn.click();
2) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
// waits are wrappers to wait until
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
sleepTheThread(10000);
String clickButton =Â
"if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('click',true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject){ arguments[0].fireEvent('onclick');}";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(clickButton, updateBtn);
3) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
// waits are wrappers to wait until
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
sleepTheThread(10000);
confirmNewPasswordField.sendKeys(Keys.TAB);
updateBtn.sendKeys(Keys.ENTER);
updateBtn.click();
4) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
// waits are wrappers to wait until
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
sleepTheThread(10000);
Actions build = new Actions(driver);
build.moveToElement(updateBtn, 3, 1).click().build().perform();
5) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
// waits are wrappers to wait until
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
sleepTheThread(10000);
new Actions(driver).moveToElement(updateBtn).click().perform();
6) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
// waits are wrappers to wait until
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
new Actions(driver).clickAndHold(updateBtn).perform();
sleepTheThread(2000);
new Actions(driver).release(updateBtn).perform();
7) Without the wrapper to sleep in Selenium, the button always gets clicked on a fast system, and intermittently fails on a slower system. If I add aÂ
10 second sleep before the click, I can get the test to always fail on the faster system.
// waits are wrappers to wait until
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", updateBtn);
This is the code for the page object class for the password change page in question...
package com.extraview.pageObject;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.FindBy;
// For logging information to the testNG HTML output and console.Â
import org.testng.Reporter;
import com.extraview.pageObject.ExtraViewLoginPage;
import com.extraview.utility.UtilityMethods;
/**
 * Class implements the Reset your Password page using the Page Object Model. Contains methods needed to access
 * a subset of the services available on the Reset your Password page. Â
 *Â
 * @author Ingmar Thompson
 *
 */
public class ExtraViewResetPasswordPage extends UtilityMethods {
// Initialize the Elements we will manipulate.
@FindBy(how=How.ID, using = "addEditTitle")
private WebElement evChangePassword;
@FindBy(name = "p_user_id")
private WebElement currentUserIdField;
@FindBy(name = "p_password")
private WebElement currentPasswordField;
@FindBy(name = "p_new_password")
private WebElement newPasswordField;
@FindBy(name = "p_confirm_new_password")
private WebElement confirmNewPasswordField;
@FindBy(xpath = "//*[@id='_buttonFooter']/tbody/tr/td[2]/table/tbody/tr/td/nobr/input[1]")
private WebElement updateBtn;
/**
* Constructor for ExtraViewResetPasswordPage.
* Switch to the correct frame, initialize the WebElements of interest, verify WebElement on page.Â
*Â
* @param driver
*/
public ExtraViewResetPasswordPage(WebDriver driver) {
// Switch to the iframe with the name main. Must go back to default otherwise cannot find main frame.
driver.switchTo().defaultContent();
driver.switchTo().frame("main");
Reporter.log("Switched to the frame containing password change fields on the Reset Password Page. | ", true);
// Use the PageFactory to initialize all the WebElements.
PageFactory.initElements(driver, this);
Reporter.log("Elements on Reset Password Page have been initialized but not found. | ", true);
}
/**
* Verify we are on the Reset Password Page. Â
*Â Â
*/
public void verifyResetPasswordPage() {
// String to hold the title of the Reset Password Page.
String resetPasswordPageTitle;
// Expected Title of Reset Password Page
String expectedResetPasswordPageTitle = getValueFromProperties("expectedResetPasswordPageTitle");
// Wait for the Change Password title to be available.
waitForElementToBeLocated(evChangePassword);
resetPasswordPageTitle = evChangePassword.getText();
// Let the Tester know we have verified we are on the Reset Password Page.
if (resetPasswordPageTitle.equals(expectedResetPasswordPageTitle)) {
Reporter.log("Verified we are on the Reset Password Page: " + resetPasswordPageTitle + " | ",true);
} else {
Reporter.log("Couldn't verify we are on the Reset Password Page. It should be"
+ " determined why you get this logging message: " + resetPasswordPageTitle + " | ",true);
}
}
public ExtraViewLoginPage resetPassword(String userId, String password, String alternatePassword) {
// Wait for the User Id field to be available.
waitForElementToBeLocated(currentUserIdField);
// Clear values for four fields on Reset Password page and enter values into fields.
fillInTextField(currentUserIdField, userId, "User ID");
fillInTextField(currentPasswordField, password, "Current password");
fillInTextField(newPasswordField, alternatePassword, "New password");
fillInTextField(confirmNewPasswordField, alternatePassword, "Confirm new Password");
// This is the code which works the best, unless there is too long of a delay clicking update.
waitForElementToBeLocated(updateBtn);
waitForElementToBeVisible(updateBtn);
waitForElementToBeClickable(updateBtn);
sleepTheThread(10000);
updateBtn.click();
//sleepTheThread(10000);
//String clickButton =Â
// "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('click',true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject){ arguments[0].fireEvent('onclick');}";
// JavascriptExecutor js = (JavascriptExecutor) driver;
// js.executeScript(clickButton, updateBtn);
/* I am moving on. I have spent hours trying to get the click update to work reliably if there is a slow
  down in clicking the update button. If the update button is clicked fast enough, the test works fine.
  If clicking the update button takes too long, then it is not correctly clicked by Selenium and theÂ
  password update fails.Â
*/
// The below are all the experiments I have been trying to get the code to work if delay to click update.
// Click the update button on the Reset Password page.
// NOTE: This click seems to be sometimes failing on the windows side to update the password.
// It is very strange, because I am see the update button being clicked and the navigation
// move on correctly.
//sleepTheThread(10000);
//found = retryingElement(By.xpath("//*[@id='_buttonFooter']/tbody/tr/td[2]/table/tbody/tr/td/nobr/input[1]"));
//if (found) {Â
// Click the edit button
//updateBtn.click();
//}
//confirmNewPasswordField.sendKeys(Keys.TAB);
//updateBtn.sendKeys(Keys.ENTER);
//updateBtn.click();
//Actions build = new Actions(driver);
//build.moveToElement(updateBtn, 3, 1).click().build().perform();
//driver.navigate().refresh();
//build.moveToElement(updateBtn, 3, 1).click().build().perform();
//new Actions(driver).moveToElement(updateBtn).click().perform();
//new Actions(driver).clickAndHold(updateBtn).perform();
//sleepTheThread(2000);
//new Actions(driver).release(updateBtn).perform();
//Actions builder = new Actions(driver);
//builder.moveToElement(updateBtn).click().build().perform();
//JavascriptExecutor executor = (JavascriptExecutor)driver;
//executor.executeScript("arguments[0].click();", updateBtn);
//if (updateBtn.isEnabled() && updateBtn.isDisplayed()) {
//Reporter.log("Clicking on element with using java script click" + " | ",true);
//((JavascriptExecutor) driver).executeScript("arguments[0].click();", updateBtn);
//} else {
//Reporter.log("Unable to click on element" + " | ",true);
//System.out.println("Unable to click on element");
//}
//waitForElementToBeClickable(updateBtn);
//new Actions(driver).moveToElement(updateBtn).click().perform();
Reporter.log("Clicking the Update button on Reset Password Page." + " | ",true);
return new ExtraViewLoginPage(driver);
}
}Â
This is the code of the page I am periodically not successful in clicking the Update button...