1

I am using selenium with IE to automate web testing. My webpage fills out a form and finally clicks a button. Code to click button is

driver.FindElement(By.CssSelector("td.ne-fieldvalues > input[type=\"button\"]")).Click();

8 out of 10 times, it Clicks but other time click command is never executed. Is there way I can check if button was indeed clicked ? something similar to checkbox

if (!driver.FindElement(By.CssSelector("input[type=\"checkbox\"]")).Selected)
                    driver.FindElement(By.CssSelector("input[type=\"checkbox\"]")).Click();

I tried .Displayed and .Enabled and both these properties are always true. Thanks for help.

2
  • What is the outcome of button click? Does the GUI state changes after click? Commented May 16, 2017 at 23:36
  • sorry for replying late. Button click pops up another window. Commented May 17, 2017 at 13:17

1 Answer 1

2

To ensure that an action is performed on a click of a link or button, it is best to verify the resultant state of application. For eg. if I click on 'Log in' button after entering valid username and password, it will take me to my homepage, verify that homepage has loaded, else fail the click event. In case of invalid username/password, verify the warning message on login page itself.

To summarize, you have to validate the response to verify click event on any web element.

The least you can do is ensure that the element is clickable using ExpectedConditions.elementToBeClickable():

// In Java
WebDriverWait wait = new WebDriverWait(driver, timeOut);
wait.until(ExpectedConditions.elementToBeClickable(locator));
Sign up to request clarification or add additional context in comments.

1 Comment

hmm ok. I understand that. I was hoping if I can use any Button property to check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.