Selenium typeKeys 从正在键入的字符串中去除点
以下指令
Selenium.typeKeys("location", "gmail.com");
键入字符串 gmailcom
而不是 gmail.com
。
那里发生了什么事?
来自评论:
我正在尝试模拟自动填充,目前在 selenium 上执行此操作的唯一方法是将 type 和 typeKey 结合起来。 例如:
selenium.type("assigned_to", split[0]+"@");
selenium.typeKeys("assigned_to", "gmail.com");
现在我的问题是为什么 typeKeys 不在 gmail.com 之间输入“点”?
The following instruction
Selenium.typeKeys("location", "gmail.com");
types the string gmailcom
instead of gmail.com
.
What's happening there?
From the comments:
I am trying to simulate autofill and the only way to do it currently on selenium is to combine type and typeKeys. eg:
selenium.type("assigned_to", split[0]+"@");
selenium.typeKeys("assigned_to", "gmail.com");
Now my question is why typeKeys doesn't type the 'dot' in between gmail.com?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您是否尝试过使用本机键功能和 javascript 字符代码?
我无法使用它们(字符 190)获得“句点”字符,但我得到了小数点(字符 110),可以正常工作,并且文本框也不应该有问题。
Have you tried using the Native key functions and javascript char codes?
I couldn't get a 'period' character to work using them (char 190), but I got the decimal (char 110) to work just fine, and the text box shouldn't have a problem with either.
使用
type
方法。来自 类型键的 javadoc:
Use the
type
method.From the javadoc for typekeys:
我们在 selenium python 中使用 typekeys 时遇到了类似的问题。
我们认为解决此问题的一种解决方法是使用“type”和“type_keys”的组合。 您可能知道,类型不存在此类问题。
我们在 selenium python 脚本中做到了这一点,它工作得很好。
例如:
如果需要在文本框中输入电子邮件地址:[电子邮件受保护]
然后做
也许是一种非常粗糙的方法,但它完成了工作。
希望这可以帮助其他遇到类似问题的人。
We had similar problems using typekeys in selenium python.
One workaround we figured to resolve this issue is to use the combination of 'type' and 'type_keys'. As you might be aware, type does not have such issues.
We did this in our selenium python script and it works just fine.
For example:
If there's an email address to be entered in a text box: [email protected]
Then do
Maybe a very crude way to do, but it did the job.
Hope this helps someone else with a similar problem.
还要尝试在写入元素之前将焦点设置在元素上。
它在我的例子中确实起作用,处理输入类型=密码。
Also try to set focus on element before write on it.
it did function in my case, handling a input type=password.
假设要使用
typeKeys
输入的字符串是“abc.xyz.efg”。 然后,我们可以使用type
和typeKeys
命令写入给定的字符串。当你想在下拉框中选择一个元素时,上面的两个步骤很有用,并且只有当我们使用 typeKeys 命令时,下拉菜单才会弹出。
Suppose the string to be typed using
typeKeys
is "abc.xyz.efg". Then, we can usetype
andtypeKeys
commands to write the given string.The above two steps are useful whenever you want to select an element in drop down box, and the drop down pops down only if we use typeKeys command.
当使用 Selenium RC (C#) 和不同的字符时,我也看到了这种行为(例如“y”,它似乎也从打字操作中删除了跟随它的字符..)
对于某些情况,完全有可能得到通过使用 TypeKeys 或 KeyPress 功能键入按键来解决该问题,但我还没有找到一种解决方案,当您想要在字段中键入文本、输入控制字符(例如 [Enter] 或换行符)时,该解决方案有效,然后键入更多文本..(在本例中使用“类型”功能只会覆盖字段内容...)。
如果有人设法找到这个问题的合理解决方案,请将其添加到这个问题中,因为它现在开始出现在谷歌中,并且可能会帮助很多人......(如果可以的话,我会开始赏金......)
I'm also seeing this behaviour when using Selenium RC (C#), and with different characters ('y' for example which also seems to remove the character follow it from the typing action..)
For some situations it is entirely possible to get around the issue by typing out the keys with the TypeKeys or KeyPress functions, but I haven't managed to find a solution that works when you want to type text in a field, enter control characters ([Enter] or a newline for example), and then type more text.. (using the 'Type' function in this case simply overwrites the field contents...).
If anyone manages to find a reasonable solution to this issue, please add it to this question as it's starting to come up in google now and would probably help alot of people out.. (I'd start a bounty if I could..)
这是 Selenium 中的一个开放错误(错误 SEL-519)。
经过一番摆弄后,我终于成功输入了“.”。 使用 JavaScript 写入文本区域。 通过
storeEval
等执行window.document.getElementById('assigned_to').value += '.'
之类的操作。This is an open bug in Selenium (bug SEL-519).
After some fiddling around with it, I finally managed to enter '.' into a textarea by using JavaScript. Execute something like
window.document.getElementById('assigned_to').value += '.'
viastoreEval
or the like.我得到了相同的行为,但通过将变量而不是字符串传递给 Type 命令来修复它。
它就像一个魅力!
I got the same behaviour but fixed it by passing a variable to the Type command instead of a string.
It works like a charm!