eclipse Selenium typeKeys 从输入的字符串中去除点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/803830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:41:05  来源:igfitidea点击:

Selenium typeKeys strips out dot from the String being typed

javaeclipsejunitselenium

提问by Afamee

The following instruction

以下指令

Selenium.typeKeys("location", "gmail.com");

types the string gmailcominstead of gmail.com.

键入字符串gmailcom而不是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 和 typeKeys。例如:

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?

现在我的问题是为什么 typeKeys 不在 gmail.com 之间输入“点”?

回答by s_hewitt

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.

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

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

回答by Alex B

Use the typemethod.

使用type方法。

From the javadoc for typekeys:

来自typekeysjavadoc

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.

这个命令可能有也可能没有任何可见的效果,即使在键入键通常会产生可见效果的情况下

...

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

回答by Rajeev

We had similar problems using typekeys in selenium python.

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

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.

我们想解决此问题的一种解决方法是使用“type”和“type_keys”的组合。您可能知道, type 没有这样的问题。

We did this in our selenium python script and it works just fine.

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

For example: If there's an email address to be entered in a text box: [email protected]

例如:如果要在文本框中输入电子邮件地址:[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.

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

回答by Abhilash

Suppose the string to be typed using typeKeysis "abc.xyz.efg". Then, we can use typeand typeKeyscommands to write the given string.

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

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.

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

回答by Luca

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.

在我的情况下它确实起作用,处理输入类型=密码。

回答by Peter Bernier

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

在使用 Selenium RC (C#) 和不同的字符时,我也看到了这种行为(例如,'y' 似乎也从打字动作中删除了跟随它的字符..)

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

在某些情况下,完全有可能通过使用 TypeKeys 或 KeyPress 函数输入键来解决该问题,但我还没有找到一种解决方案,当您想在字段中输入文本、输入控制字符(例如,[Enter] 或换行符),然后输入更多文本..(在这种情况下使用“类型”功能只会覆盖字段内容......)。

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

如果有人设法找到解决此问题的合理解决方案,请将其添加到此问题中,因为它现在开始出现在谷歌中,并且可能会帮助很多人......(如果可以的话,我会开始悬赏......)

回答by Peter Bernier

This is an open bug in Selenium (bug SEL-519).

这是 Selenium 中的一个开放错误(错误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 storeEvalor the like.

经过一番摆弄之后,我终于设法输入了'.'。使用 JavaScript 进入 textarea。执行类似window.document.getElementById('assigned_to').value += '.'viastoreEval之类的操作。

回答by Oscar

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

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

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

It works like a charm!

它就像一个魅力!