diff --git a/Selenium_Clean/Form1.cs b/Selenium_Clean/Form1.cs index 93b27e4..36aa2e0 100644 --- a/Selenium_Clean/Form1.cs +++ b/Selenium_Clean/Form1.cs @@ -13,6 +13,9 @@ using OpenQA.Selenium.Firefox; using System.IO; using System.Diagnostics; using System.Reflection; +using System.Threading; +using OpenQA.Selenium.Support.UI; +using OpenQA.Selenium.Interactions; namespace Selenium_Clean { @@ -73,16 +76,21 @@ namespace Selenium_Clean return value; } private void btnStart_Click(object sender, EventArgs e) - { - string loginCookieValue = GetCookie(COOKIE_HOST, "login"); - string loginSessionValue = GetCookie(COOKIE_HOST, "login-session"); + { + string loginCookieName = "login"; + string loginSessionCookieName = "login-session"; + string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName); + string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName); + + int windowWidth = 1920; + int windowHeight = 1080; var service = FirefoxDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory+@"geckodriver-v0.27.0-win32\geckodriver.exe"); service.Host = "127.0.0.1"; service.Port = 5555; FirefoxOptions options = new FirefoxOptions(); - options.AddArgument("--window-size=1920,1080"); + options.AddArgument("--window-size="+windowWidth+","+windowHeight+""); options.AddArgument("--disable-headless"); options.AddArgument("--disable-web-security"); options.AddArgument("--same-site-none-secure"); @@ -90,7 +98,61 @@ namespace Selenium_Clean using (var driver = new FirefoxDriver(service,options)) { - driver.Navigate().GoToUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&autoplay=1&mute=1"); + var loginCookie = new Cookie(loginCookieName, loginCookieValue, COOKIE_HOST, "/", DateTime.Now.AddDays(5)); + var loginSessionCookie = new Cookie(loginSessionCookieName, loginSessionValue, COOKIE_HOST, "/", DateTime.Now.AddDays(5)); + + Actions actions = new Actions(driver); + + driver.Navigate().GoToUrl("https://f1tv.formula1.com/"); + + driver.Manage().Cookies.AddCookie(loginCookie); + driver.Manage().Cookies.AddCookie(loginSessionCookie); + + driver.Navigate().GoToUrl("https://f1tv.formula1.com/detail/1000005104/2022-bahrain-grand-prix?action=play"); + + //Waits for the page to fully load + driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30); + + //Removes the cookie prompt + IWebElement conscentButton = driver.FindElement(By.Id("truste-consent-button")); + conscentButton.Click(); + + //Again waits for the page to fully load (when you accept cookies it takes a little time for the page to load) + //Cannot use The timeout because the feed loading is not really loading so there is not event or anything + Thread.Sleep(5000); + + //Switches to the Data channel + try + { + IWebElement dataChannelButton = driver.FindElement(By.ClassName("data-button")); + dataChannelButton.Click(); + } + catch (OpenQA.Selenium.NoSuchElementException error) + { + //If the data button does not exists its because the user is not connected + MessageBox.Show("Could not connect to the F1TV. Please connect to it using your account on chrome and if you already did please wait the process can take a few minuts"); + driver.Dispose(); + Application.Exit(); + } + //Open settings + // Press the space key twice, this should make the setting button visible + actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform(); + Thread.Sleep(1000); + //Clicks on the settings Icon + IWebElement settingsButton = driver.FindElement(By.ClassName("bmpui-ui-settingstogglebutton")); + settingsButton.Click(); + IWebElement selectElement = driver.FindElement(By.ClassName("bmpui-ui-videoqualityselectbox")); + SelectElement select = new SelectElement(selectElement); + IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']")); + selectOption.Click(); + + //Makes the feed fullscreen + IWebElement fullScreenButton = driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton")); + fullScreenButton.Click(); + + Thread.Sleep(5000); + + //Now you can start taking screenshots } } } diff --git a/Selenium_Clean/Selenium_Clean.csproj b/Selenium_Clean/Selenium_Clean.csproj index c1a12d1..bb67516 100644 --- a/Selenium_Clean/Selenium_Clean.csproj +++ b/Selenium_Clean/Selenium_Clean.csproj @@ -49,6 +49,9 @@ ..\packages\Selenium.WebDriver.4.8.2\lib\net47\WebDriver.dll + + ..\packages\Selenium.Support.4.8.2\lib\net47\WebDriver.Support.dll + diff --git a/Selenium_Clean/packages.config b/Selenium_Clean/packages.config index f11db51..df1388b 100644 --- a/Selenium_Clean/packages.config +++ b/Selenium_Clean/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file