使用C#按Selenium RC中的Enter键

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

我正在使用Selenium使用SearchBox 。 我必须在其中键入一些名称,我必须按Enter键进行搜索。

没有“ Submit按钮。 所以,我必须使用回车

我试过这样的事

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

但是不起作用。

请帮忙。

注意:我收集了一些可能的方法来执行此操作。 看到这里: 在selenium中按回车键

这可以通过Keys (单击此处获取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); 

来自Keys Enum。

试试这个:

import org.openqa.selenium.Keys

WebElement.sendKeys(Keys.RETURN)

参考文献:

在Selenium中输入Enter / Return键

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

希望这可以帮助。

这是用C#完成的:

webElement.SendKeys(Keys.Return);

试试这个:

 selenium.KeyPressNative("13"); 

我相信你也可以使用’Submit’方法。 (虽然我使用的是Selenium 2,所以我猜也许这在Selenium RC中是不可能的?对不起,如果有的话)。

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

使用这一个

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

你可以使用clickAt(“locator”,“”); 如果keyPress不工作。 它肯定会起作用。