我正在使用 C#
和 Selenium
处理一些自动化脚本,在 IE11
上运行我的测试。我试图使用 WebElement 中的 .Click()
函数点击一个链接,但它根本不起作用,所以我尝试使用 .SendKeys(Keys.Enter)
函数,它起作用了。
我试图理解这种行为,但我无法弄清楚为什么会这样。
有谁知道使用 .Click()
和 .SendKeys(Keys.Enter)
之间的区别?
最佳答案
点击()
...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.
发送 key ()
Use this method to simulate typing into an element, which may set its value.
两者都模拟用户对网络元素的操作。但是虽然 SendKeys()
尝试执行操作而不考虑任何其他事情,但 Click()
有一些安全措施,比如“停止”代码继续直到页面加载事件发生已收到。此外,该方法不会在不满足某些先决条件的情况下尝试执行以避免意外行为。
关于c# - .SendKeys(Keys.Enter) 和.Click() 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34810299/