Selenium typeKeys 从正在键入的字符串中去除点

发布于 2024-07-18 01:15:20 字数 421 浏览 5 评论 0原文

以下指令

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

独留℉清风醉 2024-07-25 01:15:20

您是否尝试过使用本机键功能和 javascript 字符代码
我无法使用它们(字符 190)获得“句点”字符,但我得到了小数点(字符 110),可以正常工作,并且文本框也不应该有问题。

selenium.Focus("assigned_to");
selenium.Type("assigned_to", split[0]+"@");
selenium.TypeKeys("assigned_to", "gmail");
selenium.KeyPressNative("110");
selenium.TypeKeys("assigned_to", "com");

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.

selenium.Focus("assigned_to");
selenium.Type("assigned_to", split[0]+"@");
selenium.TypeKeys("assigned_to", "gmail");
selenium.KeyPressNative("110");
selenium.TypeKeys("assigned_to", "com");
野心澎湃 2024-07-25 01:15:20

使用type方法。

来自 类型键的 javadoc

该命令可能有也可能没有任何
可见效果,即使在以下情况下
打字键通常会有一个
效果看得见

...

在某些情况下,您可能
需要使用简单的“type”命令
设置字段的值,然后
“typeKeys”命令发送
按键事件对应什么
您刚刚输入。

Use the type method.

From the javadoc for typekeys:

this command may or may not have any
visible effect, even in cases where
typing keys would normally have a
visible effect

...

In some cases, you may
need to use the simple "type" command
to set the value of the field and then
the "typeKeys" command to send the
keystroke events corresponding to what
you just typed.

薯片软お妹 2024-07-25 01:15:20

我们在 selenium python 中使用 typekeys 时遇到了类似的问题。

我们认为解决此问题的一种解决方法是使用“type”和“type_keys”的组合。 您可能知道,类型不存在此类问题。

我们在 selenium python 脚本中做到了这一点,它工作得很好。

例如:
如果需要在文本框中输入电子邮件地址:[电子邮件受保护]

然后做

type(locator,’[email protected].’)
type_keys(locator,’uk’)

也许是一种非常粗糙的方法,但它完成了工作。

希望这可以帮助其他遇到类似问题的人。

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

type(locator,’[email protected].’)
type_keys(locator,’uk’)

Maybe a very crude way to do, but it did the job.

Hope this helps someone else with a similar problem.

沧笙踏歌 2024-07-25 01:15:20

还要尝试在写入元素之前将焦点设置在元素上。

selenium.focus(locator);
selenium.typeKeys(locator, value);

它在我的例子中确实起作用,处理输入类型=密码。

Also try to set focus on element before write on it.

selenium.focus(locator);
selenium.typeKeys(locator, value);

it did function in my case, handling a input type=password.

我ぃ本無心為│何有愛 2024-07-25 01:15:20

假设要使用 typeKeys 输入的字符串是“abc.xyz.efg”。 然后,我们可以使用 typetypeKeys 命令写入给定的字符串。

type(locator,"abc.xyz.")
typeKeys(locator,"efg")

当你想在下拉框中选择一个元素时,上面的两个步骤很有用,并且只有当我们使用 typeKeys 命令时,下拉菜单才会弹出。

Suppose the string to be typed using typeKeys is "abc.xyz.efg". Then, we can use type and typeKeys commands to write the given string.

type(locator,"abc.xyz.")
typeKeys(locator,"efg")

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.

瑕疵 2024-07-25 01:15:20

当使用 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..)

与酒说心事 2024-07-25 01:15:20

这是 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 += '.' via storeEval or the like.

意中人 2024-07-25 01:15:20

我得到了相同的行为,但通过将变量而不是字符串传递给 Type 命令来修复它。

string email = @"[email protected]";
selenium.Type(inputfield, email);

它就像一个魅力!

I got the same behaviour but fixed it by passing a variable to the Type command instead of a string.

string email = @"[email protected]";
selenium.Type(inputfield, email);

It works like a charm!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文