c# - .SendKeys(Keys.Enter) 和.Click() 之间的区别?

标签 c# selenium selenium-webdriver

我正在使用 C#Selenium 处理一些自动化脚本,在 IE11 上运行我的测试。我试图使用 WebElement 中的 .Click() 函数点击一个链接,但它根本不起作用,所以我尝试使用 .SendKeys(Keys.Enter) 函数,它起作用了。

我试图理解这种行为,但我无法弄清楚为什么会这样。

有谁知道使用 .Click().SendKeys(Keys.Enter) 之间的区别?

最佳答案

来自documentation

点击()

...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/

相关文章:

python - 如何使用 Selenium 和 xpath 或其他替代方案从 url 获取包含动态数据的表?

c# - 创建用户时出错 - ASP.NET System.Web.Providers

java - 从电子商务网站中提取 Web 元素?

php - Yii Framework testing with PHPUnit and Selenium 错误/警告

testing - 如何使用 WebDriver 单击元素

ios - 无法单击 Appium iOS 中 facebook 弹出窗口的 "OK"按钮

java - parent sibling 的xpath

c# - 允许在 .NET TreeView 中进行多选

c# - 为什么这个 catch all block 实际上并没有 catch all

c# - 如何在 HttpWebRequest POST 中将对象作为参数传递?