'.NET Selenium bet365 login fails with correct credentials

I am trying to log into bet365 with .NET and selenium.

After i started the login with the correct credentials (i tried them manual), bet365 tells me that i entered invalid credentials. I think this happens cause bet365 detects that i am using Selenium.

I already tried to disable some stuff which would tell bet365 that i am using Selenium.

This is the code i am using:

public class GameDataScraper {
        public void GetTeamData() {
            ChromeOptions options = new ChromeOptions();
            options.AddArgument("start-maximized");
            options.AddArgument("disable-infobars");

            options.AddExcludedArgument("enable-automation");

            using (var driver = new ChromeDriver(@"C:\Program Files (x86)", options)) {
                driver.Navigate().GoToUrl("https://www.bet365.com/#/IP/B151");
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

                Thread.Sleep(2000);

                AcceptCookies(driver);
                Login(driver);

                Console.WriteLine();
            }
        }

        public void AcceptCookies(WebDriver driver) {
            var acceptButton = driver.FindElement(By.ClassName("ccm-CookieConsentPopup_Accept"));
            acceptButton.Click();
        }

        public void Login(WebDriver driver) {
            var elements = driver.FindElements(By.XPath("//*[contains(text(),'Einloggen')]"));
            foreach(var element in elements) {
                if (element.Text.Equals("Einloggen")) {
                    element.Click();
                    break;
                }
            }

            var usernameElement = driver.FindElement(By.ClassName("lms-StandardLogin_Username"));
            SendKeysToInputField(usernameElement, "username");
            var passwordElement = driver.FindElement(By.ClassName("lms-StandardLogin_Password"));
            SendKeysToInputField(passwordElement, "password");
            passwordElement.SendKeys(Keys.Enter);
            var loginButton = driver.FindElement(By.ClassName("lms-LoginButton_Text"));
            loginButton.Click();
        }

        public void SendKeysToInputField(IWebElement element, string text) {
            foreach(char c in text) {
                element.SendKeys(c.ToString());
                Thread.Sleep(350);
            }
        }
    }

I already tried to trick them by using a delay for input but this doesnt work too.

Any help is appreciated



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source