7

我正在尝试使用 nunit + Selenium + c# 创建一个自动化框架

我们的网络管理员基于 Devexpress 框架,因此我无法通过它的“ID”单击按钮,或者至少我不知道如何操作。对此的替代方法是简单地按下“Enter”按钮。我已经试过了

driver.FindElement(By.XPath("String")).SendKeys(Keys.Enter);
4

4 回答 4

7
using OpenQA.Selenium.Interactions;

Actions builder = new Actions(driver);        
builder.SendKeys(Keys.Enter);

有关更多信息:在 Selenium 中键入 Enter/Return 键

于 2016-06-24T06:31:11.027 回答
1

使用下面的代码单击一个不可见的按钮。

 IWebElement tmpElement = Driver.FindElement(By.Id("invisibleButton"));
 var executor = (IJavaScriptExecutor)Driver;
 executor.ExecuteScript("arguments[0].click();", tmpElement);
 wait.Until(d => { return d.Title.Equals("pageTitle"); });
于 2015-06-30T06:10:28.837 回答
0

RON,在调用 GoToUrl 之后,DOM 可能需要一些时间来加载。增加隐式等待时间,以便 findElement 在抛出任何异常之前等待更多时间。或者使用明确的 wiat --- http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

如果这仍然不起作用,那么使用 Actions 类 -- http://www.guru99.com/keyboard-mouse-events-files-webdriver.html

于 2013-07-10T03:27:26.907 回答
0

Keys.Return()解决了压制的问题enter

于 2020-06-16T16:05:45.043 回答