Automating login with Selenium

Our company has an internal tool that loads up various dashboards using Selenium ChromeDriver, logs in with the correct credentials, and displays the dashboard on a TV. I’m trying to add a hosted Grafana dashboard to it but it’s not logging in correctly.

I load the playlist URL and end up at the screen with the only button of “Log in with Grafana.com”. That gets clicked and then we’re at the login screen where we enter the username/password. I find the Log In button and click it but it just redirects back to the first page. If I use my mouse on that login screen and click the exact same button, it loads the dashboard correctly. Am I missing something?

var formElement = driver.FindElement(By.ClassName("login-form"));
var buttonElement = formElement.FindElement(By.XPath("//button[@class='btn btn--primary btn--large']"));
Actions builder = new Actions(driver);
builder.MoveToElement(buttonElement).Click(buttonElement);
builder.Perform();

The code was fine, the problem was from a different bug in my implementation.

1 Like