0

I am automating login page for a bootstrap UI. I want to take a screenshot each time when Login button gets click in Chrome and IE browser after loading a full page. In Firefox its working properly, I can see a next page in the screenshot.

Below is my code:

[TestMethod]
public void LoginTestChrome(string userName, string pwd)
{
  OpenBrowserChrome();
  IWebElement username = driver.FindElement(By.Id("Label"));
  username.SendKeys(userName);
  IWebElement password = driver.FindElement(By.Id("Pwd"));
  password.SendKeys(pwd);
  driver.FindElement(By.Id("BtnLogin")).Click();
  SaveScreenshot();
  driver.Quit();
}

Can anyone solve my problem please?

  • What automation tool you are using? – Rahul Jha Oct 26 '15 at 12:11
  • I am doing it in Visual studio 2013 – Shraddha Arondekar Oct 26 '15 at 12:13
  • can you post your button click – Ajay Pandya Oct 26 '15 at 12:18
  • [TestMethod] public void LoginTestChrome(string userName, string pwd) { OpenBrowserChrome(); IWebElement username = driver.FindElement(By.Id("Label")); username.SendKeys(userName); IWebElement password = driver.FindElement(By.Id("Pwd")); password.SendKeys(pwd); driver.FindElement(By.Id("BtnLogin")).Click(); SaveScreenshot(); driver.Quit(); } – Shraddha Arondekar Oct 26 '15 at 12:24
  • Possible duplicate of [Reliably detect page load or time out, Selenium 2](http://stackoverflow.com/questions/18729483/reliably-detect-page-load-or-time-out-selenium-2) – Rahul Jha Oct 26 '15 at 12:32

1 Answers1

0

You have to write code to ensure that the page is properly loaded. You can verify that a Web Element is present on the new page.

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
wait.Until(drv => drv.FindElement(by));

with this code, you are sure that for every browser, Selenium will wait for the element -> page loaded.

KR,

Nicolas

Nicolas G. Duvivier
  • 498
  • 1
  • 6
  • 18
  • I tried putting waits in this but still it doesn't work. And to fine element for explicit wait, I don't have any as I am testing login page. When login fails, It should remain on that page only and take screenshot of validation messages given – Shraddha Arondekar Nov 03 '15 at 12:41
  • Maybe you can wait for this message to appear ? you wait for this to be visible, and then you take a sreenshot. Did you tried this ? – Nicolas G. Duvivier Nov 03 '15 at 15:09