Pressing Ctrl+A in Selenium WebDriver

前端 未结 13 955
一向
一向 2020-11-27 02:45

I need to press Ctrl+A keys using Selenium WebDriver. Is there any way to do it?

I checked the Selenium libraries and found that Selenium allow

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 03:39

    Since Ctrl+A maps to ASCII code value 1 (Ctrl+B to 2, up to, Ctrl+Z to 26).

    Try:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using OpenQA.Selenium;
    using OpenQA.Selenium.IE;
    using OpenQA.Selenium.Support.UI;
    using OpenQA.Selenium.Interactions;
    using OpenQA.Selenium.Internal;
    using OpenQA.Selenium.Remote;
    
    namespace SeleniumHqTest
    {
        class Test
        {
                IWebDriver driver = new InternetExplorerDriver();
                driver.Navigate().GoToUrl("http://localhost");
                IWebElement el = driver.FindElement(By.Id("an_element_id"));
                char c = '\u0001'; // ASCII code 1 for Ctrl-A
                el.SendKeys(Convert.ToString(c));
                driver.Quit();
        }
    }
    

提交回复
热议问题