0

I have html code for button like below

<button class="btn btn-mini" onclick="setLive()">

I would like to write a selenium script which could check whether the button is clicked or not. could someone tell me how could I write a script in selenium webdriver.

1
  • This site is not a free programming site. You have to show us what you tried.
    – Jack M.
    Jun 11, 2014 at 15:40

2 Answers 2

0

I don't believe that Selenium can actually tell whether a button has been clicked as that information is visible only to the browser itself. Selenium is designed to attempt actions through the browser interface and then validate the results. The behavior you want does not fall within this concept. The proper thing to do here is not attempt to figure out if the browser has detected a button click, but to validate the expected results upon clicking the button (whatever those user-visible results may be). That's the proper way to test application behavior. Verifying that a button has successfully sent a click signal to the browser process won't help you if the expected results don't manifest.

As for how to do that... you're going to have to do some reading and start learning Java, C#, Python, or one of the other myriad languages that the Selenium library supports.

0

onClick() events not gets executed when you just perform click() function on WebElement.

You should try this:

WebElement btn=driver.findElement(By.className("btn btn-mini")); JavascriptExecuter jse=(JavascriptExecuter)driver; jse.executeScript("arguments[0].click();",btn);

Your Answer

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

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