使用 C# 在 Selenium RC 中按 Enter 键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10243153/
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-08-09 13:02:07  来源:igfitidea点击:

Press Enter Key in Selenium RC with C#

c#seleniumselenium-rckeypressenter

提问by Ranadheer Reddy

How to press Enter using Selenium RC using C#?

如何使用 C# 使用 Selenium RC 按 Enter 键?

I am working with a SearchBoxusing Selenium. In which I have to type some name and I have to press Enterto search.

我正在SearchBox使用 using Selenium。我必须在其中输入一些名称,然后按下Enter才能进行搜索。

There is no Submitbutton. So, I must use Enter.

没有Submit按钮。所以,我必须使用Enter.

I tried something like this

我试过这样的事情

selenium.KeyPress("quicksearchtextcriteria", "13");

But doesn't work.

但不起作用。

Please Help.

请帮忙。

Note: I made a collection of possible ways to do this. See here: press enter key in selenium

注意:我收集了一些可能的方法来做到这一点。在这里看到:在硒中按回车键

采纳答案by Petr Jane?ek

This can be achieved by Keys, and Enter.

这可以通过Keys、 和来实现Enter

Example in Java as I don't know C#:

Java 中的示例,因为我不知道 C#:

import org.openqa.selenium.Keys;

//...

// this sends an Enter to the element
selenium.type("locator", Keys.ENTER);

// or even this - this sends the "Any text" and then confirms it with Enter
selenium.type("locator", "Any text" + Keys.ENTER);

From the Keysenum.

Keys枚举。

回答by Alp

Try this:

尝试这个:

selenium.KeyPressNative("13");

回答by Rohit Ware

Use this one

用这个

selenium.keyDown("locator of element", "\13");

回答by Nashibukasan

I believe you can also use the 'Submit' method. (Though I use Selenium 2, so I'm guessing perhaps this is not possible in Selenium RC? Sorry if so).

我相信您也可以使用“提交”方法。(虽然我使用 Selenium 2,所以我猜这在 Selenium RC 中可能是不可能的?对不起,如果是这样)。

//First you need to find the searchBox and fill it, once doing so call
searchBox.Submit();

回答by Amit Shakya

You can use clickAt("locator",""); If keyPress is not working. It will work for sure.

您可以使用 clickAt("locator",""); 如果 keyPress 不起作用。它肯定会起作用。

回答by AlphaMale

Try this:

尝试这个:

import org.openqa.selenium.Keys

WebElement.sendKeys(Keys.RETURN)

导入 org.openqa.selenium.Keys

WebElement.sendKeys(Keys.RETURN)

References:

参考:

Typing Enter/Return key in Selenium

在 Selenium 中输入 Enter/Return 键

http://asynchrony.blogspot.com/2008/11/enter-key-press-in-selenium.html

http://asyncchrony.blogspot.com/2008/11/enter-key-press-in-selenium.html

Hope this helps.

希望这可以帮助。

回答by Illidan

This is how it done with C#:

这是用 C# 完成的:

webElement.SendKeys(Keys.Return);

webElement.SendKeys(Keys.Return);