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


C# Actions.SendKeys方法代码示例

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


在下文中一共展示了Actions.SendKeys方法的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: KeyboardKeysExample

    public void KeyboardKeysExample()
    {
        Driver.Navigate().GoToUrl("http://the-internet.herokuapp.com/key_presses");

        // Option 1
        Driver.FindElement(By.Id("content")).SendKeys(Keys.Space);
        Assert.That(Driver.FindElement(By.Id("result")).Text.Equals("You entered: SPACE"));

        // Option 2
        Actions Builder = new Actions(Driver);
        Builder.SendKeys(Keys.Left).Build().Perform();
        Assert.That(Driver.FindElement(By.Id("result")).Text.Equals("You entered: LEFT"));
    }
开发者ID:GruLab,项目名称:elemental-selenium-tips,代码行数:13,代码来源:KeyboardKeys.cs

示例3: ShouldAllowBasicKeyboardInput

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

            IWebElement keyReporter = driver.FindElement(By.Id("keyReporter"));

            Actions actionProvider = new Actions(driver);
            IAction sendLowercase = actionProvider.SendKeys(keyReporter, "abc def").Build();

            sendLowercase.Perform();

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

示例4: IfNoObjectInClipboardCtrlVRevertsToBrowserBehaviour

 public virtual void IfNoObjectInClipboardCtrlVRevertsToBrowserBehaviour() {
     GeminiUrl("home?m1=EmployeeRepository&d1=CreateNewEmployeeFromContact&f1_contactDetails=null");
     WaitForView(Pane.Single, PaneType.Home);
     var home = WaitForCss(".title");
     Actions action = new Actions(br);
     action.DoubleClick(home); //Should put "Home"into browser clipboard
     action.SendKeys(Keys.Control + "c");
     action.Perform();
     Thread.Sleep(500);
     //home.SendKeys(Keys.Control + "c");
     string selector = "input.value";
     var target = WaitForCss(selector);
     Assert.AreEqual("", target.GetAttribute("value"));
     target.Click();
     target.SendKeys(Keys.Control + "v");
     Assert.AreEqual("Home", target.GetAttribute("value"));
 }
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:17,代码来源:LocallyRunTests.cs

示例5: launchAttack


//.........这里部分代码省略.........
                        MessageBox.Show( "Failed to convert flood attacks to INT32!" );
                        MessageBox.Show( "CurrentAttacks: " + sCurrentAttacks );
                        MessageBox.Show( "CurrentMaxAttacks: " + sMaxAttacks );
                        return true;
                    }

                    if( curAttacks >= maxAttacks ) { // reload site to refresh attack box
                        driver.Navigate().Refresh();
                        await Task.Delay( 4500 );
                        //System.Threading.Thread.Sleep( 4500 );

                        launchAttack = false;
                    } else { launchAttack = true; }
                }
            }
            */
            #endregion

            try { // check if site has crashed
                driver.FindElement( By.ClassName( "cf-wrapper" ) ); // if found, then site has crashed
                Program.formInstance.setAction( "Site has crashed, reloading after 1 minute!" );
                await Task.Delay( TimeSpan.FromMinutes(1) );
                driver.Navigate().Refresh();
                await Task.Delay( TimeSpan.FromSeconds( 10 ) );
            } catch( NoSuchElementException e ) {
                // no action.
            }

            IWebElement inputBox = null;
            try
            {
                inputBox = driver.FindElement( By.ClassName( "block-content-form") );
            } catch( NoSuchElementException e ){
                Program.formInstance.setAction( "Failed to find input box!" );
                return true;
            }

            IList<IWebElement> labels = inputBox.FindElements( By.TagName("label") );
            if( labels.Count <= 0 ) {
                Program.formInstance.setAction( "Failed to find label elements!" );
                return true;
            }

            // INPUTTING DATA INTO BOXES
            IWebElement IPBox   = null; // ip to attack
            IWebElement PortBox = null; // port to attack
            IWebElement TimeBox = null; // how long to attack
            
            foreach( IWebElement e in labels ) {
                if( e.Text.Contains( "Target IP" ) )
                    IPBox = e;

                if( e.Text.Contains( "Target Port" ) )
                    PortBox = e;

                if( e.Text.Contains( "Time" ) )
                    TimeBox = e;
            }

            if( IPBox == null | PortBox == null | TimeBox == null ) {
                Program.formInstance.setAction( "Failed to find all input boxes!" );
                return true;
            }

            Actions action = new Actions( driver ); // make mouse move

            IWebElement temp = IPBox.FindElement( By.TagName("input" ) );
            action.MoveToElement( temp ).Click().Build().Perform();
            action.SendKeys( IP ).Build().Perform();
            await Task.Delay( 500 );

            temp = PortBox.FindElement( By.TagName( "input" ) );
            action.MoveToElement( temp ).Click().Build().Perform();
            action.SendKeys( "80" ).Build().Perform();
            await Task.Delay( 500 );

            temp = TimeBox.FindElement( By.TagName( "input" ) );
            action.MoveToElement( temp ).Click().Build().Perform();
            action.SendKeys( time ).Build().Perform();
            await Task.Delay( 500 );

            temp = inputBox.FindElement( By.TagName( "button" ) );

            try {
                action.MoveToElement( temp ).Click().Build().Perform();
            }catch( Exception e ) {
                return true;
            }

            try {
                WebDriverWait wait = new WebDriverWait( driver, TimeSpan.FromMinutes(1) );
                wait.Until( d => ( (IJavaScriptExecutor)driver ).ExecuteScript( "return document.readyState" ).Equals( "complete" ) );
            } catch( Exception e ) {
                Program.formInstance.setAction( "Failed to wait for page refresh!" );
                return true;
            }


            return false;
        }
开发者ID:exploder2013,项目名称:CSharp-Booter,代码行数:101,代码来源:Main.cs

示例6: Main

        static void Main(string[] args)
        {
            driver = new ChromeDriver();

            driver.Manage().Window.Maximize();

            driver.Navigate().GoToUrl(baseURL + "/");

            Login();

            Thread.Sleep(2000);
            driver.FindElement(By.Id("epi-quickNavigator-clickHandler")).Click();
            Thread.Sleep(1000);
            driver.FindElement(By.XPath("//ul[@id='epi-quickNavigator']//li[@class='epi-quickNavigator-dropdown']//ul[@id='epi-quickNavigator-menu']//a[text()='CMS Edit']")).Click();

            Thread.Sleep(2000);
            NavigateToNewCatalogUI();

            Thread.Sleep(2000);

            ToggleNavigationPan();
            //ExpandCatalogRoot();
            ExpandCategory(
            new string[]{
                "Catalog Root", "Departmental Catalog", "Departments", "Media", "Music",
            });
            HoverCategoryTree("Music-Soundtrack");
            Click_Tab_AllProperties("Assets");
            //PlaceOrder();

            //var ul = driver.FindElement(By.Id("epi-quickNavigator-menu"));
            //Console.WriteLine(ul.GetAttribute("style"));
            //var links = ul.FindElements(By.TagName("a"));
            //var li = ul.FindElements(By.TagName("li"));
            //foreach (var link in links)
            //{
            //    Console.WriteLine(link.Text);
            //}

            //var dashBoardLink = links.First(element => element.Text == "Dashboard");
            //Console.WriteLine(dashBoardLink.Location);

            //var cmsEditLink = links.First(element => element.Text == "CMS Edit");
            //Console.WriteLine(cmsEditLink.Location);

            //OpenGlobalMenu();
            return;

            var span = driver.FindElement(By.Id("uniqName_26_46"));

            Console.WriteLine(span != null);
            var sParent = span.FindElement(By.XPath("./parent::*"));
            if (sParent != null)
            {
                Console.WriteLine("hjeheheheh");
                Console.WriteLine(sParent.GetAttribute("data-dojo-attach-event"));
                Actions actions = new Actions(driver);
                actions.MoveToElement(sParent);//.Build().Perform();
                actions.Click().Perform();
                var pin = driver.FindElement(By.Id("dijit_form_ToggleButton_6"));
                var pPin = pin.FindElement(By.XPath("./parent::*"));
                if (pPin != null)
                {
                    Console.WriteLine(pPin.GetAttribute("data-dojo-attach-event"));
                    actions.MoveToElement(pPin);//.Build().Perform();
                    actions.Click().Perform();
                }
            }
            var treeDiv = driver.FindElement(By.Id("navigation"));
            if (treeDiv != null)
            {
                Actions actions1 = new Actions(driver);
                Console.WriteLine("left tree can be recorgnied");
                var homePageNode = treeDiv.FindElement(By.XPath("//span[contains(@title, '2526')]"));
                actions1.MoveToElement(homePageNode.FindElement(By.XPath("./parent::*")));
                actions1.Click().Perform();

                //Create content
                var createButton = driver.FindElement(By.XPath("//span[contains(@title, 'Create content')]"));
                actions1.MoveToElement(createButton.FindElement(By.XPath("./parent::*")));
                actions1.Click().Perform();

                var newPageRow = driver.FindElement(By.Id("uniqName_26_47"));
                actions1.MoveToElement(newPageRow);
                actions1.Click().Perform();
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
                //data-dojo-attach-point="namePanel"
                var namePanelDiv = driver.FindElement(By.XPath("//div[contains(@data-dojo-attach-point, 'namePanel')]//div[contains(@class, 'dijitReset dijitInputField dijitInputContainer')]"));

                if (namePanelDiv != null)
                {
                    //dijitReset dijitInputField dijitInputContainer
                    var newPageInput = namePanelDiv.FindElement(By.TagName("input"));
                    Console.WriteLine(newPageInput.GetAttribute("id"));

                    actions1.MoveToElement(newPageInput);
                    actions1.Click().Perform();

                    actions1.SendKeys(Keys.Backspace);
                    actions1.SendKeys(Keys.Backspace);
//.........这里部分代码省略.........
开发者ID:ntdung,项目名称:EPiServerCommerce75,代码行数:101,代码来源:Program.cs

示例7: Type

 public void Type(string text)
 {
     EnsureFocus();
     Actions action = new Actions(this.Driver);
     action.SendKeys(text);
     action.Perform();
 }
开发者ID:Jarga,项目名称:Alias,代码行数:7,代码来源:SeleniumWebPage.cs

示例8: 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

示例9: TypeKeyss

 public void TypeKeyss(string keys)
 {
     Actions actionProvider = new Actions(driver);
     actionProvider.SendKeys(keys);
 }
开发者ID:BrockFredin,项目名称:SeleniumLW,代码行数:5,代码来源:Textfield.cs

示例10: PressKey

        public static void PressKey(string key)
        {
            var builder = new Actions(SeleniumDriver.Instance);

            switch (key.ToLower())
            {
                case "return":
                    builder.SendKeys(Keys.Return);
                    break;
                case "tab":
                    builder.SendKeys(Keys.Tab);
                    break;
                case "arrowdown":
                    builder.SendKeys(Keys.ArrowDown);
                    break;
                case "arrowup":
                    builder.SendKeys(Keys.ArrowUp);
                    break;
                case "arrowleft":
                    builder.SendKeys(Keys.ArrowLeft);
                    break;
                case "arrowright":
                    builder.SendKeys(Keys.ArrowRight);
                    break;
                case "home":
                    builder.SendKeys(Keys.Home);
                    break;
                case "end":
                    builder.SendKeys(Keys.End);
                    break;
                case "pageup":
                    builder.SendKeys(Keys.PageUp);
                    break;
                case "pagedown":
                    builder.SendKeys(Keys.PageDown);
                    break;
            }


            builder.Build().Perform();
        }
开发者ID:rohanbaraskar,项目名称:SeleniumAutomationFramework,代码行数:41,代码来源:SeleniumHelper.cs

示例11: PressEscapeKey

 /// <summary>
 /// Presses the keyboard Escape key
 /// </summary>
 public static void PressEscapeKey()
 {
     var action = new Actions(Driver.Instance);
     action.SendKeys(Keys.Escape);
     Driver.Wait(TimeSpan.FromSeconds(1));
 }
开发者ID:pmavrogiannis,项目名称:JustPhoneBook_Framework,代码行数:9,代码来源:Commands.cs

示例12: ShouldAllowSendingKeysToActiveElement

        public void ShouldAllowSendingKeysToActiveElement()
        {
            driver.Url = bodyTypingPage;

            Actions actionProvider = new Actions(driver);
            IAction someKeys = actionProvider.SendKeys("ab").Build();
            someKeys.Perform();

            IWebElement bodyLoggingElement = driver.FindElement(By.Id("body_result"));
            Assert.AreEqual("keypress keypress", bodyLoggingElement.Text);

            IWebElement formLoggingElement = driver.FindElement(By.Id("result"));
            Assert.AreEqual("", formLoggingElement.Text);
        }
开发者ID:akiellor,项目名称:selenium,代码行数:14,代码来源:BasicKeyboardInterfaceTest.cs

示例13: startWallBoard

        private void startWallBoard(object sender, RoutedEventArgs e)
        {
            // Configure the WebDriver path, and set to invisble (avoids annoying cmd prompt pop-up
            DriverService driverService = ChromeDriverService.CreateDefaultService(@".\WebDrivers\");
            driverService.HideCommandPromptWindow = true;

            // Use default chrome options for kiosk mode
            ChromeOptions cOptions = new ChromeOptions();
            //cOptions.AddArgument("--start-maximized --kiosk");
            //cOptions.BinaryLocation = "CHROME DIRECTORY";

            //IWebDriver driver = new ChromeDriver(@".\WebDrivers\");
            IWebDriver driver = new ChromeDriver(service: (ChromeDriverService)driverService, options: cOptions);

            //Create the actions builder
            Actions builder = new Actions(driver);

            //Default Site
            Thread.Sleep(100);
            Debug.Print(driver.CurrentWindowHandle);
            driver.SwitchTo().Window(driver.CurrentWindowHandle);
            Thread.Sleep(100);
            driver.Navigate().GoToUrl("http://www.reddit.com");
            Thread.Sleep(100);

            //Create some tabs
            driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
            Thread.Sleep(200);
            driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
            Thread.Sleep(200);
            driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
            Thread.Sleep(200);

            //List the open tabs
            List<String> openTabs = openTabs = driver.WindowHandles.ToList<string>(); //driver.WindowHandles is a bloody read only collection
            foreach (var item in openTabs)
            {
                Debug.Print(item);
            }
            Debug.Print("TAB list size is  {0} ", openTabs.Count);

            Thread.Sleep(200);
            driver.SwitchTo().Window(openTabs[1]);
            Debug.Print("Switching to {0}", driver.Title);
            driver.Navigate().GoToUrl("http://www.facebook.com");
            Debug.Print("I am now to {0}", driver.Title);

            Thread.Sleep(200);
            driver.SwitchTo().Window(openTabs[2]);
            Debug.Print("Switching to {0}", driver.Title);
            driver.Navigate().GoToUrl("http://www.test.com");
            Debug.Print("I am now to {0}", driver.Title);

            Thread.Sleep(200);
            driver.SwitchTo().Window(openTabs[3]);
            Debug.Print("Switching to {0}", driver.Title);
            driver.Navigate().GoToUrl("http://www.baesystems.com");
            Debug.Print("I am now to {0}", driver.Title);

            Thread.Sleep(200);

            //Go to next tab (loop to first)
            Thread.Sleep(100);
            builder.SendKeys(Keys.Control + Keys.PageDown).Perform();
            driver.SwitchTo().Window(openTabs[0]);
            Thread.Sleep(100);
            driver.SwitchTo().ActiveElement();
            Debug.Print("BOLLOXX {0}", driver.Title);
            Thread.Sleep(100);

            //Hide the main app window
            this.frmMain.WindowState = System.Windows.WindowState.Minimized;
        }
开发者ID:RAGNOARAKNOS,项目名称:WallBoards,代码行数:73,代码来源:MainWindow.xaml.cs

示例14: AddItemInline

        /// <summary>
        /// Basic inline product addition simulation. Adds one product to an empty MyCart grid.
        /// Uses Selenium Actions to interact with MyCart grid.
        /// </summary>
        /// <param name="pnToAdd">Product number to add. May need to have an extra same starting letter
        /// as the Action is too fast to register the first.
        /// </param>
        /// <returns>Current page</returns>
        internal MyCartPage AddItemInline(string pnToAdd, string affiliation)
        {
            _logger.Trace(" > Attempting to add a product inline...");
            AlertSuccess = false; 
            Thread.Sleep(1000);
            IWebElement PNCell, Outside, Active;
            try
            {
                PNCell = HelperMethods.FindElement(_driver, Constants.SearchType.XPATH, Constants.MyCart.XP.EDITABLE_ROW);
                Outside = HelperMethods.FindElement(_driver, Constants.SearchType.ID, Constants.MyCart.XP.CART_ORDER_GRID);
                // Enter Product Number into cell
                Actions action = new Actions(_driver);
                action.MoveToElement(PNCell).Click().SendKeys(pnToAdd).Perform();
                // Tab over to quantity
                if (affiliation.Equals(Constants.Affiliation.Drake.USER))
                    action.SendKeys(Keys.Tab).SendKeys(Keys.Tab).SendKeys(Keys.Tab).SendKeys(Keys.Tab).SendKeys(Keys.Tab).SendKeys(Keys.Tab).Perform();
                else
                    action.SendKeys(Keys.Tab).Perform();
                // Add quantity and complete product entry
                Thread.Sleep(500);
                Active = HelperMethods.FindElement(_driver, Constants.SearchType.XPATH, Constants.MyCart.XP.ACTIVE_ROW_QTY);
                action.MoveToElement(Active).Click().SendKeys(Keys.Tab).Perform();
                Thread.Sleep(500);
                AlertSuccess = HelperMethods.CheckAlert(_driver);
                if (AlertSuccess.Equals(true))
                    _logger.Info(" > Product added inline!");
                else
                    _logger.Info(" > Problem adding product inline!");
            }
            catch (Exception e)
            {
                _logger.Error(" > Exception encountered AddItemInLine(): " + e.Message);
            }

            return this;
        }
开发者ID:milan-lbmx,项目名称:LBMXRegressionAutomation,代码行数:44,代码来源:MyCartPage.cs

示例15: KeyboardSendKeys

 public void KeyboardSendKeys(string code)
 {
     Console.WriteLine("Send key '" + code + "' from keyboard");
     var builder = new Actions(Driver);
     builder.SendKeys(code).Perform();
 }
开发者ID:AlexNaryzhny,项目名称:helloci,代码行数:6,代码来源:BasePage.cs


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