I'm using selenium 2.24
Firefox Driver to test an input box's blur event. Currently, after I sendKeys
to an input box, I let selenium to click another area which triggers the input box blur.
However, I think it is not a good way, anyone knows a better way to test this?
Many thanks.
Step 1: Navigate to the official Selenium website. Under third-party drivers, one will find all the drivers. Just click on the Mozilla GeckoDriver documentation as shown below. Now, it will navigate to the GeckoDriver downloads link, where one can download the suitable driver based on the OS as it is platform agnostic.
Marionette is an automation driver for Mozilla's Gecko engine. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox.
Step 1: Selenium FirefoxDriver or Selenium GeckoDriver can be downloaded from the official GitHub repository of Mozilla. Go to the link and scroll towards the bottom of the page. Open the Assets menu and download the Selenium FirefoxDriver respective to your operating system. Step 2: Extract the downloaded file.
Next, go to https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/Support.html and check for required Firefox version supported by Selenium and Gecko driver: In my case, Selenium Webdriver version is 3.9. 1, so the supported Firefox browser is version 55+ and gecko driver supported is version 0.20. 1.
The selenium WebDriver does not properly trigger events like blur. You can, however, manually trigger them. Assuming that you're using jquery:
firefoxWebDriver.executeScript("$('#yourID').blur()");
Or without jquery:
firefoxWebDriver.executeScript("document.querySelector('#yourID').blur()");
Some elements do not have a suitable discriminator for testing purposes (e.g. an id or another CSS selector that you'd like to be bound to in your tests).
Fortunately, the notion of an activeElement exisits. So, if the element's blur functionality is what you wish to test, a native javascript way (not reliant upon jQuery or similar) to test this is:
driver.ExecuteScript("!!document.activeElement ? document.activeElement.blur() : 0");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With