Skip to content

No reaction to website login with Selenium

I can login to the PHP website https://panel-support.oasgames.com/panel/ajaxrela/login manually, which will show a bird animation and on failed login show “Failed to login” on the website, whereas on successful login it will redirect to the main page. Login happens via POST, which returns JSON. But when I use the following executable snippet and login in the automated Chrome window (manually or using selenium commands), the bird animation shows but nothing else happens on failed or successful login. (Feel free to test that with bogus login data). Commented out commands are for logging in via selenium, here with bogus login data:

    private static IWebDriver driver = new ChromeDriver();

    static void Main(string[] args)
    {
        driver.Navigate().GoToUrl("http://panel-support.oasgames.com/panel/ajaxrela/login");
        //WebDriverWait wait = new WebDriverWait(driver, new System.TimeSpan(0, 0, 30));
        //wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy((By
            .Name("username"))));
        //driver.FindElement(By.Id("username")).SendKeys("foo");
        //driver.FindElement(By.Id("password")).SendKeys("bar");
        //driver.FindElement(By.TagName("button")).Click();
        Thread.Sleep(10000);
        driver.Quit();
    }

Advertisement

Answer

Your selector for username and password are incorrect. They should be By.Name().

driver.FindElement(By.Name("username")).SendKeys("foo");
driver.FindElement(By.Name("password")).SendKeys("bar");
driver.FindElement(By.TagName("button")).Click();
User contributions licensed under: CC BY-SA
2 People found this is helpful