예제 #1
0
        public void CrossBrowserDemo()
        {
            IWebDriver driver;

            //driver = new ChromeDriver();
            //driver = new FirefoxDriver();
            // driver = new InternetExplorerDriver();
            // driver = new EdgeDriver(); // legacy

            //https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ for edge
            //https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium // new edge chromium
            // Make sure you download the chromium msedgedriver.exe from the above link for new chromium edge
            // for legacy follow the cmd prompt instruction to enble legacy webdriver as mentioned in above link.

            var options = new Microsoft.Edge.SeleniumTools.EdgeOptions();

            options.UseChromium    = true;
            options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge Beta\Application\msedge.exe";


            driver = new Microsoft.Edge.SeleniumTools.EdgeDriver(options);



            driver.Url = "https://abrakh.com/";
            driver.Manage().Window.Maximize();
            Console.WriteLine(driver.Title);
        }
예제 #2
0
파일: Form2.cs 프로젝트: DyHon/CS511.L11
        private void button2_Click(object sender, EventArgs e)
        {
            SoundPlayer SP = new SoundPlayer(@Application.StartupPath + @"\Data\Music\Sou\Nguoi than.wav");

            SP.Play();



            var driverservice = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService();

            driverservice.HideCommandPromptWindow = true;

            var options = new Microsoft.Edge.SeleniumTools.EdgeOptions();

            options.UseChromium    = true;
            options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";

            var driver = new Microsoft.Edge.SeleniumTools.EdgeDriver(driverservice, options);

            driver.Url = "https://www.messenger.com/login/";
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            IWebElement query = driver.FindElement(By.CssSelector("#email"));

            query.SendKeys("ldh2210");
            query = driver.FindElement(By.CssSelector("#pass"));
            query.SendKeys("lehoang2210kt");
            query = driver.FindElement(By.CssSelector("#loginbutton"));
            query.Click();
            driver.Navigate().GoToUrl("https://www.messenger.com/t/100012544930422");

            query = driver.FindElement(By.XPath(".//*[@role = 'presentation']"));
            query.Click();

            //driver.Quit();
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified <see cref="EdgeDriverService"/>.
 /// </summary>
 /// <param name="service">The <see cref="EdgeDriverService"/> to use.</param>
 /// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options, service.UsingChromium))
 {
     // Add the custom commands unique to Chromium
     this.AddCustomChromiumCommand(GetNetworkConditionsCommand, CommandInfo.GetCommand, "/session/{sessionId}/chromium/network_conditions");
     this.AddCustomChromiumCommand(SetNetworkConditionsCommand, CommandInfo.PostCommand, "/session/{sessionId}/chromium/network_conditions");
     this.AddCustomChromiumCommand(DeleteNetworkConditionsCommand, CommandInfo.DeleteCommand, "/session/{sessionId}/chromium/network_conditions");
     this.AddCustomChromiumCommand(SendChromiumCommand, CommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command");
     this.AddCustomChromiumCommand(SendChromiumCommandWithResult, CommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
 }
예제 #4
0
        static void downloadReport()
        {
            Console.WriteLine("Downloading Report ...");
            String url = "https://www.who.int/healthinfo/statistics/data/en/";
            //Setup
            EdgeOptions edgeOptions = new Microsoft.Edge.SeleniumTools.EdgeOptions();

            edgeOptions.UseChromium = true;
            //edgeOptions.AddUserProfilePreference()
            //edgeOptions.AddArgument("headless");
            IWebDriver _driver = new Microsoft.Edge.SeleniumTools.EdgeDriver("./files/drivers", edgeOptions);

            //Open Browser
            _driver.Url = url;
            Console.WriteLine(_driver.Title);

            //Download Excel
            IReadOnlyList <IWebElement> listExcel = _driver.FindElement(By.Id("primary")).FindElements(By.TagName("A"));

            Console.WriteLine(listExcel.Count.ToString());

            //Extract Data from Excel and Store in DB
            foreach (IWebElement item in listExcel)
            {
                Console.WriteLine(item.Text);
                item.Click();

                System.Threading.Thread.Sleep(4000);

                //Wait for the alert to be displayed and store it in a variable
                //Alert alert = wait.until(ExpectedConditions.alertIsPresent());

                //Type your message
                //alert.sendKeys("Selenium");

                //Press the OK button
                //alert.dismiss();

                break;
            }

            //Tear Down
            _driver?.Quit();
            _driver?.Dispose();
        }
예제 #5
0
        private static ICapabilities ConvertOptionsToCapabilities(EdgeOptions options, bool serviceUsingChromium)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "options must not be null");
            }

            if (serviceUsingChromium != options.UseChromium)
            {
                if (serviceUsingChromium)
                {
                    throw new WebDriverException("options.UseChromium must be set to true when using an Edge Chromium driver service.");
                }
                else
                {
                    throw new WebDriverException("options.UseChromium must be set to false when using an Edge Legacy driver service.");
                }
            }

            return(options.ToCapabilities());
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified options.
 /// </summary>
 /// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
 public EdgeDriver(EdgeOptions options)
     : this(EdgeDriverService.CreateDefaultServiceFromOptions(options), options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified
 /// <see cref="EdgeDriverService"/> and options.
 /// </summary>
 /// <param name="service">The <see cref="EdgeDriverService"/> to use.</param>
 /// <param name="options">The <see cref="EdgeOptions"/> used to initialize the driver.</param>
 public EdgeDriver(EdgeDriverService service, EdgeOptions options)
     : this(service, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified path
 /// to the directory containing the WebDriver executable, options, and command timeout.
 /// </summary>
 /// <param name="edgeDriverDirectory">The full path to the directory containing the WebDriver executable.</param>
 /// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public EdgeDriver(string edgeDriverDirectory, EdgeOptions options, TimeSpan commandTimeout)
     : this(EdgeDriverService.CreateDefaultServiceFromOptions(edgeDriverDirectory, options), options, commandTimeout)
 {
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified path
 /// to the directory containing the WebDriver executable and options.
 /// </summary>
 /// <param name="edgeDriverDirectory">The full path to the directory containing the WebDriver executable.</param>
 /// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
 public EdgeDriver(string edgeDriverDirectory, EdgeOptions options)
     : this(edgeDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
 /// <summary>
 /// Creates a default instance of the EdgeDriverService using a specified path to the WebDriver executable with the given name and listening port.
 /// </summary>
 /// <param name="driverPath">The directory containing the WebDriver executable.</param>
 /// <param name="driverExecutableFileName">The name of the WebDriver executable file</param>
 /// <param name="port">The port number on which the driver will listen</param>
 /// <returns>A EdgeDriverService using the specified port.</returns>
 public static EdgeDriverService CreateDefaultServiceFromOptions(string driverPath, string driverExecutableFileName, int port, EdgeOptions options)
 {
     return(new EdgeDriverService(driverPath, driverExecutableFileName, port, options.UseChromium));
 }
        /// <summary>
        /// Creates a default instance of the EdgeDriverService using a specified path to the WebDriver executable with the given name.
        /// </summary>
        /// <param name="driverPath">The directory containing the WebDriver executable.</param>
        /// <param name="driverExecutableFileName">The name of the WebDriver executable file.</param>
        /// <returns>A EdgeDriverService using a random port.</returns>
        public static EdgeDriverService CreateDefaultServiceFromOptions(string driverPath, string driverExecutableFileName, EdgeOptions options)
        {
            // Locate a free port on the local machine by binding a socket to
            // an IPEndPoint using IPAddress.Any and port 0. The socket will
            // select a free port.
            int    listeningPort = 0;
            Socket portSocket    = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                IPEndPoint socketEndPoint = new IPEndPoint(IPAddress.Any, 0);
                portSocket.Bind(socketEndPoint);
                socketEndPoint = (IPEndPoint)portSocket.LocalEndPoint;
                listeningPort  = socketEndPoint.Port;
            }
            finally
            {
                portSocket.Close();
            }

            return(CreateDefaultServiceFromOptions(driverPath, driverExecutableFileName, listeningPort, options));
        }
 /// <summary>
 /// Creates a default instance of the EdgeDriverService using a specified path to the WebDriver executable.
 /// </summary>
 /// <param name="driverPath">The directory containing the WebDriver executable.</param>
 /// <returns>A EdgeDriverService using a random port.</returns>
 public static EdgeDriverService CreateDefaultServiceFromOptions(string driverPath, EdgeOptions options)
 {
     return(CreateDefaultServiceFromOptions(driverPath, EdgeDriverServiceFileName(options.UseChromium), options));
 }
        /// <summary>
        /// Creates a default instance of the EdgeDriverService.
        /// </summary>
        /// <returns>A EdgeDriverService that implements default settings.</returns>
        public static EdgeDriverService CreateDefaultServiceFromOptions(EdgeOptions options)
        {
            string serviceDirectory = DriverService.FindDriverServiceExecutable(EdgeDriverServiceFileName(options.UseChromium), MicrosoftWebDriverDownloadUrl);

            return(CreateDefaultServiceFromOptions(serviceDirectory, options));
        }