Automating login with Selenium

treycarroll
Giga Guru

Hello,

 

I'm playing around with Selenium and I would like to automate the login for my "Hello World".   If anybody has experience with automating ServiceNow testing with the FirefoxDriver, how do we deal with finding the elements in the the iFrame?

 

Thanks,

 

Trey Carroll

4 REPLIES 4

jesusemelendezm
Mega Guru

I am interesting to know about it too.


Hi Jesus,



Here is what I have so far for the login piece:



var driver = new FirefoxDriver();


driver.Navigate().GoToUrl("https://mycompany.service-now.com/navpage.do");


driver.SwitchTo().Frame("gsft_main");



FirefoxWebElement e = driver.FindElement(By.Id("user_name")) as FirefoxWebElement;


e.SendKeys("myusername");



FirefoxWebElement e2 = driver.FindElementsById("user_password").First() as FirefoxWebElement;


e2.SendKeys("password");



FirefoxWebElement loginButton = driver.FindElementsById("sysverb_login").First() as FirefoxWebElement;


loginButton.Click();


With this you are able to log in to the instance?


Hi Jesus,



Yes.     This code opens up Firefox and logs into ServiceNow.   The missing step would be to add an assert that confirms that some element on the page that is only visible to someone who is logged in is present on the page.



Regards,



Trey Carroll