当前位置: 首页>>代码示例>>C#>>正文


C# Actions.KeyDown方法代码示例

本文整理汇总了C#中OpenQA.Selenium.Interactions.Actions.KeyDown方法的典型用法代码示例。如果您正苦于以下问题:C# Actions.KeyDown方法的具体用法?C# Actions.KeyDown怎么用?C# Actions.KeyDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenQA.Selenium.Interactions.Actions的用法示例。


在下文中一共展示了Actions.KeyDown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldAllowSendingKeysWithShiftPressed

        public void ShouldAllowSendingKeysWithShiftPressed()
        {
            driver.Url = javascriptPage;

            IWebElement keysEventInput = driver.FindElement(By.Id("theworks"));

            keysEventInput.Click();

            Actions actionProvider = new Actions(driver);
            IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build();
            pressShift.Perform();

            IAction sendLowercase = actionProvider.SendKeys(keysEventInput, "ab").Build();
            sendLowercase.Perform();

            IAction releaseShift = actionProvider.KeyUp(keysEventInput, Keys.Shift).Build();
            releaseShift.Perform();

            AssertThatFormEventsFiredAreExactly("focus keydown keydown keypress keyup keydown keypress keyup keyup");

            Assert.AreEqual("AB", keysEventInput.GetAttribute("value"));
        }
开发者ID:Goldcap,项目名称:Constellation,代码行数:22,代码来源:BasicKeyboardInterfaceTest.cs

示例2: ShouldAllowSelectingMultipleItems

        public void ShouldAllowSelectingMultipleItems()
        {
            driver.Url = selectableItemsPage;

            IWebElement reportingElement = driver.FindElement(By.Id("infodiv"));

            Assert.AreEqual("no info", reportingElement.Text);

            ReadOnlyCollection<IWebElement> listItems = driver.FindElements(By.TagName("li"));

            Actions actionBuider = new Actions(driver);
            IAction selectThreeItems = actionBuider.KeyDown(Keys.Control)
                .Click(listItems[1])
                .Click(listItems[3])
                .Click(listItems[5])
                .KeyUp(Keys.Control).Build();

            selectThreeItems.Perform();

            Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text);

            // Now click on another element, make sure that's the only one selected.
            actionBuider.Click(listItems[6]).Build().Perform();
            Assert.AreEqual("#item7", reportingElement.Text);
        }
开发者ID:Goldcap,项目名称:Constellation,代码行数:25,代码来源:CombinedInputActionsTest.cs

示例3: ShouldAllowSelectingMultipleItems

        public void ShouldAllowSelectingMultipleItems()
        {
            if (!IsNativeEventsEnabled || (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Linux)))
            {
                Assert.Ignore("Skipping ShouldAllowSelectingMultipleItems: Only works with native events on Linux.");
            }

            driver.Url = selectableItemsPage;

            IWebElement reportingElement = driver.FindElement(By.Id("infodiv"));

            Assert.AreEqual("no info", reportingElement.Text);

            ReadOnlyCollection<IWebElement> listItems = driver.FindElements(By.TagName("li"));

            Actions actionBuider = new Actions(driver);
            IAction selectThreeItems = actionBuider.KeyDown(Keys.Control)
                .Click(listItems[1])
                .Click(listItems[3])
                .Click(listItems[5])
                .KeyUp(Keys.Control).Build();

            selectThreeItems.Perform();

            Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text);

            // Now click on another element, make sure that's the only one selected.
            actionBuider.Click(listItems[6]).Build().Perform();
            Assert.AreEqual("#item7", reportingElement.Text);
        }
开发者ID:draculavlad,项目名称:selenium,代码行数:30,代码来源:CombinedInputActionsTest.cs

示例4: ZoomBackToNormal

 public static void ZoomBackToNormal()
 {
     Actions zoomBackToNormal = new Actions(Browser.Driver);
     zoomBackToNormal.KeyDown(Keys.Control)
         .SendKeys("0")
         .KeyUp(Keys.Control);
     zoomBackToNormal.Perform();
 }
开发者ID:ivsontiago,项目名称:ContactFormQAWorks,代码行数:8,代码来源:Utilities.cs

示例5: ZoomOut

 public static void ZoomOut()
 {
     Actions zoomOut = new Actions(Browser.Driver);
     zoomOut.KeyDown(Keys.Control)
         .SendKeys(Keys.Subtract)
         .SendKeys(Keys.Subtract)
         .KeyUp(Keys.Control);
     zoomOut.Perform();
 }
开发者ID:ivsontiago,项目名称:ContactFormQAWorks,代码行数:9,代码来源:Utilities.cs

示例6: ShouldAllowSendingKeyDownOnly

        public void ShouldAllowSendingKeyDownOnly()
        {
            driver.Url = javascriptPage;

            IWebElement keysEventInput = driver.FindElement(By.Id("theworks"));

            Actions actionProvider = new Actions(driver);

            IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build();
            pressShift.Perform();

            IWebElement keyLoggingElement = driver.FindElement(By.Id("result"));
            string logText = keyLoggingElement.Text;

            IAction releaseShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build();
            releaseShift.Perform();

            Assert.IsTrue(logText.EndsWith("keydown"), "Key down event not isolated, got: " + logText);
        }
开发者ID:Goldcap,项目名称:Constellation,代码行数:19,代码来源:BasicKeyboardInterfaceTest.cs

示例7: ShouldAllowSendingKeyUp

        public void ShouldAllowSendingKeyUp()
        {
            driver.Url = javascriptPage;
            IWebElement keysEventInput = driver.FindElement(By.Id("theworks"));

            Actions actionProvider = new Actions(driver);
            IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build();
            pressShift.Perform();

            IWebElement keyLoggingElement = driver.FindElement(By.Id("result"));

            string eventsText = keyLoggingElement.Text;
            Assert.IsTrue(keyLoggingElement.Text.EndsWith("keydown"), "Key down should be isolated for this test to be meaningful. Event text should end with 'keydown', got events: " + eventsText);

            IAction releaseShift = actionProvider.KeyUp(keysEventInput, Keys.Shift).Build();

            releaseShift.Perform();

            eventsText = keyLoggingElement.Text;
            Assert.IsTrue(keyLoggingElement.Text.EndsWith("keyup"), "Key up event not isolated. Event text should end with 'keyup', got: " + eventsText);
        }
开发者ID:Rameshnathan,项目名称:selenium,代码行数:21,代码来源:BasicKeyboardInterfaceTest.cs

示例8: Click

        /// <summary>
        /// Method to click on button and Link
        ///
        /// </summary>
        public void Click(Dictionary<int, string> keyWordDic = null, string data = null)
        {
            try
            {
                _testObject = WaitAndGetElement();
                DateTime startTime = DateTime.Now;
                if (Utility.GetParameter("runbyevents").Equals("true"))
                {
                    switch (Browser.BrowserName.ToLower())
                    {
                        case "ie":
                        case "iexplore":
                            ExecuteScript(_testObject, "arguments[0].click();");
                            try
                            {
                                WaitForObjectNotPresent(Utility.GetVariable("ObjectTimeout"),
                                                             Utility.GetVariable("GlobalTimeout"), keyWordDic);
                            }
                            catch
                            {
                                //Nothing to throw in this case
                            }
                            break;
                        default:
                            _testObject.Click();
                            break;
                    }
                }
                else
                {
                    try
                    {
                        // Perform Shift+Click only if Shift key is passed as Data for action sheet data in case Chrome.
                        if ("Shift".Equals(data, StringComparison.OrdinalIgnoreCase) && Browser.BrowserName.Equals(KryptonConstants.BROWSER_CHROME, StringComparison.OrdinalIgnoreCase))
                        {
                            Actions objAction = new Actions(Driver);

                            objAction = objAction.KeyDown(Keys.Shift).Click(_testObject).KeyUp(Keys.Shift);
                            objAction.Build();
                            objAction.Perform();
                        }
                        else
                        {
                            _testObject.Click();
                        }

                        // Pause here for .5 sec as on mac safari VerifyTextOnPage after this looks at the page click is on and assumes that page has been received from server
                        // find a better way to do this
                        if (Browser.BrowserName.Equals("safari"))
                            Thread.Sleep(2000);
                    }
                    catch (ElementNotVisibleException enve)
                    {
                        try { ExecuteScript(_testObject, "arguments[0].click();"); }
                        catch { throw enve; }

                    }
                    catch (Exception e)
                    {
                        if (e.Message.ToLower().Contains(Exceptions.ERROR_NORESPONSEURL))
                        {
                            _testObject.Click();
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                //measure total time and raise exception if timeout is more than the allowed limit
                DateTime finishTime = DateTime.Now;
                double totalTime = (finishTime - startTime).TotalSeconds;
                if (keyWordDic != null)
                    foreach (string modifiervalue in keyWordDic.Values)
                    {
                        if (modifiervalue.ToLower().Contains("timeout="))
                        {
                            double timeout = double.Parse(modifiervalue.Split('=').Last());
                            if (totalTime > timeout)
                            {
                                throw new Exception("Page load took " + totalTime.ToString(CultureInfo.InvariantCulture) + " seconds to load against expected time of " + timeout + " seconds.");
                            }
                            Property.Remarks = "Page load took " + totalTime.ToString(CultureInfo.InvariantCulture) + " seconds to load against expected time of " + timeout + " seconds.";
                        }
                    }
            }
            catch (Exception e)
            {
                if (_objDataRow.ContainsKey(KryptonConstants.TEST_OBJECT))
                {
                    KryptonException.Writeexception(e);
                    throw new NoSuchElementException(Utility.GetCommonMsgVariable("KRYPTONERRCODE0067").Replace("{MSG3}", _objDataRow[KryptonConstants.TEST_OBJECT]).Replace("{MSG4}", _objDataRow["parent"]).Replace("{MSG1}", AttributeType).Replace("{MSG2}", Attribute).Replace("{ErrorMsg}", e.Message)); // added by
                }
                throw;
            }
//.........这里部分代码省略.........
开发者ID:Thinksys,项目名称:krypton,代码行数:101,代码来源:TestObject.cs

示例9: SelectAll

 public void SelectAll(NgWebDriver driver)
 {
     Actions action = new Actions(driver.WrappedDriver);
     IAction chord = action.KeyDown(_ele.WrappedElement, OpenQA.Selenium.Keys.Control)
         .SendKeys("a")
         .KeyUp(_ele.WrappedElement, OpenQA.Selenium.Keys.Control)
         .Build();
     chord.Perform();
 }
开发者ID:Nickkaczmarek,项目名称:EvaluationApp,代码行数:9,代码来源:PageObjectBase.cs

示例10: KeysTest

        public void KeysTest()
        {
            List<string> keyComboNames = new List<string>()
            {
                "Control",
                "Shift",
                "Alt",
                "Control + Shift",
                "Control + Alt",
                "Shift + Alt",
                "Control + Shift + Alt"
            };

            List<string> colorNames = new List<string>()
            {
                "red",
                "green",
                "lightblue",
                "yellow",
                "lightgreen",
                "silver",
                "magenta"
            };

            List<List<string>> modifierCombonations = new List<List<string>>()
            {
                new List<string>() { Keys.Control },
                new List<string>() { Keys.Shift },
                new List<string>() { Keys.Alt },
                new List<string>() { Keys.Control, Keys.Shift },
                new List<string>() { Keys.Control, Keys.Alt },
                new List<string>() { Keys.Shift, Keys.Alt },
                new List<string>() { Keys.Control, Keys.Shift, Keys.Alt}
            };

            List<string> expectedColors = new List<string>()
            {
                "rgba(255, 0, 0, 1)",
                "rgba(0, 128, 0, 1)",
                "rgba(173, 216, 230, 1)",
                "rgba(255, 255, 0, 1)",
                "rgba(144, 238, 144, 1)",
                "rgba(192, 192, 192, 1)",
                "rgba(255, 0, 255, 1)"
            };

            bool passed = true;
            string errors = string.Empty;

            driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("keyboard_shortcut.html");
            IWebElement body = driver.FindElement(By.CssSelector("body"));
            Actions actions = new Actions(driver);
            for (int i = 0; i < keyComboNames.Count; i++)
            {
                for (int j = 0; j < modifierCombonations[i].Count; j++)
                {
                    actions.KeyDown(modifierCombonations[i][j]);
                }

                actions.SendKeys("1");
                
                // Alternatively, the following single line of code would release
                // all modifier keys, instead of looping through each key.
                // actions.SendKeys(Keys.Null);
                for (int j = 0; j < modifierCombonations[i].Count; j++)
                {
                    actions.KeyUp(modifierCombonations[i][j]);
                }

                actions.Perform();
                string background = body.GetCssValue("background-color");
                passed = passed && background == expectedColors[i];
                if (background != expectedColors[i])
                {
                    if (errors.Length > 0)
                    {
                        errors += "\n";
                    }

                    errors += string.Format("Key not properly processed for {0}. Background should be {1}, Expected: '{2}', Actual: '{3}'",
                        keyComboNames[i],
                        colorNames[i],
                        expectedColors[i],
                        background);
                }
            }

            Assert.IsTrue(passed, errors);
        }
开发者ID:Rameshnathan,项目名称:selenium,代码行数:89,代码来源:IeSpecificTests.cs

示例11: ClearBrowserCache

 public static void ClearBrowserCache()
 {
     // Use Ctrl + F5
     // Logger.WriteInformationToLog("Clearing Cache - using Ctrl + F5");
     var builder = new Actions(SeleniumDriver.Instance);
     builder.KeyDown(Keys.Control).SendKeys(Keys.F5).KeyUp(Keys.Control).Perform();
 }
开发者ID:rohanbaraskar,项目名称:SeleniumAutomationFramework,代码行数:7,代码来源:SeleniumHelper.cs

示例12: ShouldHandleMultiSelect

 public void ShouldHandleMultiSelect()
 {
     Actions actions = new Actions(ngDriver.WrappedDriver);
     GetPageContent("ng_multi_select.htm");
     IWebElement element = ngDriver.FindElement(NgBy.Model("selectedValues"));
     // use core Selenium
     IList<IWebElement> options = new SelectElement(element).Options;
     IEnumerator<IWebElement> etr = options.Where(o => Convert.ToBoolean(o.GetAttribute("selected"))).GetEnumerator();
     while (etr.MoveNext())
     {
         Console.Error.WriteLine(etr.Current.Text);
     }
     foreach (IWebElement option in options)
     {
         // http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/AllMembers_T_OpenQA_Selenium_Keys.htm
         actions.KeyDown(Keys.Control).Click(option).KeyUp(Keys.Control).Build().Perform();
         // triggers ngDriver.WaitForAngular()
         Assert.IsNotEmpty(ngDriver.Url);
     }
     // re-read select options
     element = ngDriver.FindElement(NgBy.Model("selectedValues"));
     options = new SelectElement(element).Options;
     etr = options.Where(o => Convert.ToBoolean(o.GetAttribute("selected"))).GetEnumerator();
     while (etr.MoveNext())
     {
         Console.Error.WriteLine(etr.Current.Text);
     }
 }
开发者ID:sergueik,项目名称:protractor-net,代码行数:28,代码来源:LocalFileTests.cs

示例13: CtrlClick_Should_Open_Link_In_Other_Window

		public void CtrlClick_Should_Open_Link_In_Other_Window()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			dr.Navigate().GoToUrl("http://www.a.com/link.htm");
			Assert.That(dr.WindowHandles.Count == 1);
			Assert.That(dr.Url == "http://www.a.com/link.htm");

			var link = dr.FindElement(By.LinkText("link"));
			Assert.NotNull(link);
			link.Click();
			Assert.That(dr.Url == "http://www.a.com/otherpage.htm");
			dr.Navigate().Back();
			Assert.That(dr.Url == "http://www.a.com/link.htm");
			link = dr.FindElement(By.LinkText("link"));

			Actions builder = new Actions(dr);
			builder.KeyDown(Keys.Control).Click(link).KeyUp(Keys.Control);
			var act = builder.Build();
			act.Perform();

			Assert.That(dr.Url == "http://www.a.com/link.htm");
			Assert.That(dr.WindowHandles.Count == 2);

		}
开发者ID:wip-alex,项目名称:SimpleBrowser.WebDriver,代码行数:25,代码来源:SimpleNavigateTests.cs

示例14: OpenNewBrowserTab

 public void OpenNewBrowserTab()
 {
     Actions action = new Actions(this.driver);
     action.KeyDown(Keys.LeftControl).KeyDown("T").KeyUp("T").KeyUp(Keys.LeftControl).Build().Perform();
 }
开发者ID:aliaksandr-trush,项目名称:csharp-automaton,代码行数:5,代码来源:UIUtil.cs

示例15: TestKeyBoard

        public void TestKeyBoard()
        {
            NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
            Actions act = new Actions(ObjectRepository.Driver);

            // ctrl + t
            // act.KeyDown(Keys.LeftControl)
            //    .SendKeys("t")
            //    .KeyUp(Keys.LeftControl)
            //    .Build()
            //    .Perform();

            // ctrl + shift +a

            // act.KeyDown(Keys.LeftControl)
            //    .KeyDown(Keys.LeftShift)
            //    .SendKeys("a")
            //    .KeyUp(Keys.LeftShift)
            //    .KeyUp(Keys.LeftControl)
            //    .Build()
            //    .Perform();

            // alt + f + x

            // act.KeyDown(Keys.LeftAlt)
            //    .SendKeys("f")
            //    .SendKeys("x")
            //    .Build()
            //    .Perform();
            IWebElement ele1 = ObjectRepository.Driver.FindElement(By.Id("quicksearch_top"));
            IWebElement ele2 = ObjectRepository.Driver.FindElement(By.Id("quicksearch_main"));
            ele1.SendKeys("fx");

            act.KeyDown(ele2, Keys.LeftShift)
                .SendKeys(ele2, "f")
                .SendKeys(ele2, "x")
                .KeyUp(ele2, Keys.LeftShift)
                .Build()
                .Perform();
            Thread.Sleep(5000);
        }
开发者ID:Saltorel,项目名称:BDD-CSharp,代码行数:41,代码来源:TestMouseAction.cs


注:本文中的OpenQA.Selenium.Interactions.Actions.KeyDown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。