发布:2020/9/25 9:57:20作者:管理员 来源:本站 浏览次数:1148
- public static void press(params string[] keys)
- {
- foreach (string key in keys)
- {
- WebDriver.SwitchTo().ActiveElement().SendKeys(key);
- Thread.Sleep(TimeSpan.FromSeconds(2));
- }
- }
我称之为:
- press(Keys.Tab,Keys.Tab,Keys.Tab);
它工作正常.哪一种更好?
- public void Wait(double delay,double interval)
- {
- // Causes the WebDriver to wait for at least a fixed delay
- var now = DateTime.Now;
- var wait = new WebDriverWait(myWebDriver,TimeSpan.FromMilliseconds(delay));
- wait.PollingInterval = TimeSpan.FromMilliseconds(interval);
- wait.Until(wd=> (DateTime.Now - now) - TimeSpan.FromMilliseconds(delay) > TimeSpan.Zero);
- }
以某种方式观察DOM总是更好,例如:
- public void Wait(Func<IWebDriver,bool> condition,double delay)
- {
- var ignoredExceptions = new List<Type>() { typeof(StaleElementReferenceException) };
- var wait = new WebDriverWait(myWebDriver,TimeSpan.FromMilliseconds(delay)));
- wait.IgnoreExceptionTypes(ignoredExceptions.ToArray());
- wait.Until(condition);
- }
- public void SelectionIsDoneDisplayingThings()
- {
- Wait(driver => driver.FindElements(By.ClassName("selection")).All(x => x.Displayed),250);
- }
© Copyright 2014 - 2025 柏港建站平台 ejk5.com. 渝ICP备16000791号-4