I am working with some automation scripts using C#
and Selenium
, running my tests on IE11
. I was trying to click on a link using the .Click()
function from WebElement and it wasn't working at all so I tried to use the .SendKeys(Keys.Enter)
function and it worked.
I'm trying to understand this behavior but I can't figure out why is this happening.
Does anyone know the difference between using .Click()
and .SendKeys(Keys.Enter)
?
From the documentation
Click()
...If this causes a new page to load, this method will attempt to block until the page has loaded. At this point, you should discard all references to this element and any further operations performed on this element will throw a StaleElementReferenceException...
...There are some preconditions for an element to be clicked. The element must be visible and it must have a height and width greater then 0.
SendKeys()
Use this method to simulate typing into an element, which may set its value.
Both simulate user action on the web element. But while SendKeys()
tries to perform the action without consideration to anything else Click()
has some safe guards, like "stopping" the code from continue until page load event is received. Also, the method won't try to execute without meeting some preconditions to avoid unexpected behavior.
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