使用Selenium WebDriver模拟ENTER或RETURN的最佳实践是什么 [英] What is the best practice to simulate an ENTER or RETURN using Selenium WebDriver
问题描述
我遇到了此解决方案,这是我最初遇到的问题使用Selenium WebDriver模拟ENTER或RETURN键.
I came across this solution to my initial problem, which was to simulate an ENTER or RETURN key press using Selenium WebDriver.
但是,在我的代码中,我严格只想使用两个WebElement.sendKeys(Keys.ENTER);
vs WebElement.sendKeys(Keys.RETURN);
之一.
However, in my code, I strictly want to use only one of the two WebElement.sendKeys(Keys.ENTER);
vs WebElement.sendKeys(Keys.RETURN);
.
进行相同操作时的最佳实践是什么,因为对于使用enter或return似乎存在分歧,因为两者都在同一时间工作?在哪种情况下,一种或另一种都不起作用,有没有一种总是可行的?
What is the best practice when doing the same, since there seems to be divided opinion about using enter or return, since both work MOST of the time? In what scenarios would one or the other not work, and is there one which would ALWAYS work?
推荐答案
就性能而言,我在这两个方面都没有任何改变,
As a performancewise I do not get any change on both of these,
但是是的,我知道他们之间的区别
But yes I know one difference on them
Keys.Enter
用于在数字键盘上输入键
Keys.Enter
is used to enter key on the number pad
同时
Keys.Return
用于字母旁边的一个
通常我更喜欢Keys.Enter
,因为有时在某些浏览器中Keys.Return
对我不起作用
Generally I have preferred Keys.Enter
as sometimes in some browser Keys.Return
is not worked for me
这篇关于使用Selenium WebDriver模拟ENTER或RETURN的最佳实践是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!