What is the difference between type() and typeKeys() in WebDriver?



  • As both of them do the same activity is there any special differences between type and typekeys in selenium webdriver.

    wdBacked.type(locator, value);
    
    wdBacked.typeKeys(locator, value);
    


  • type
    

    void type(java.lang.String locator, java.lang.String value) Sets the value of an input field, as though you typed it in.

    Inputs the value. Sets the textfield to the value, nothing special. It just takes the entire string and puts it in there at one time.

    typeKeys
    

    void typeKeys(java.lang.String locator, java.lang.String value) Simulates keystroke events on the specified element, as though you typed the value key-by-key.

    Simulates each keystroke. So if the page has an action that occurs as you type (for example, google's autosuggest), this will be the action you would need. There is also other places where this may be useful but not too many overall.

    They are very similar and generally speaking your going to want to use type unless you need to simulate each keystrokes for a reason.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2