我正在尝试使用nunit + Selenium + c#创建自动化测试框架。
我们的Web管理界面基于Devexpress框架,因此我无法通过“ID”点击按钮,或者至少我不知道如何操作。解决方法是简单地按下“Enter”按钮。
我已经尝试过
driver.FindElement(By.XPath("String")).SendKeys(Keys.Enter);
我正在尝试使用nunit + Selenium + c#创建自动化测试框架。
我们的Web管理界面基于Devexpress框架,因此我无法通过“ID”点击按钮,或者至少我不知道如何操作。解决方法是简单地按下“Enter”按钮。
我已经尝试过
driver.FindElement(By.XPath("String")).SendKeys(Keys.Enter);
using OpenQA.Selenium.Interactions;
Actions builder = new Actions(driver);
builder.SendKeys(Keys.Enter);
更多信息请查看:如何在Selenium中输入回车/换行键
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"); });
RON,有可能是GoToUrl调用后DOM需要加载一段时间。增加隐式等待时间,以便findElement在抛出任何异常之前等待更长的时间。或者使用显式等待 --- http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp
如果仍然不起作用,则使用Actions类 -- http://www.guru99.com/keyboard-mouse-events-files-webdriver.html
Keys.Return()
解决了按下 enter
的问题
.Click
不起作用呢? - Arrandriver.FindElement(By.Id("pcLogin_Panel1_btnLogon_B")).Click(); Assert.AreEqual("Web Admin - Dashboard", driver.Title);
} - RON12345