I'm automating a part of the User Profile UI we have using WebDriver Selenium 2, I'm coding in Visual Studio so I am using the .Net version as I am more comfortable in C#, and I am testing this with IE8. Part of the problem I am having is that the User Profile page using tabs to actively display User Address information or User Interests - the flow that happens when going through the page is that the User Address information appears then after a Save Changes button is selected the User Interests tab is then made active. I'd like to make a small change in the User Address information, get to the User Interests and just save all changes by selecting the button on the User Interests page. Since its all one page, and just the active tabs change what information is displayed, the problem I am encountering with Web Driver is that the Elements become stale by the time I get to User Interests.
Basically the page is set up so that Tab1 - User Address, Tab2 - User Interests. Only one is actively displayed at one time.
Is there a way to refresh the elements? I am already doing FindElements when the page updates to pull in the Page Elements, I thought this would do a DOM refresh but that does not seem to be happening. Originally I thought this was a JQuery problem, as the Interests page has three Taxonomy drop downs that are populated, but I've finally isolated it to the button being unable to be selected, even through FindElements seems to return something. When I go to use Sendkeys on the button I usually get an Element is no longer valid error.
I believe if I was able to refresh the DOM then this would go away.
The code I am using is:
while (!((IJavaScriptExecutor)driver).ExecuteScript("return jQuery.active;").ToString().Equals("0"));
Assert.True(driver.PageSource.Contains("Topics of Interest"));
wait.Until(webDriver => driver.FindElement(By.Id("ctl00_PlaceHolderMain_SavePersonalizationButton")));
IWebElement saveButton2 = driver.FindElement(By.Id("ctl00_PlaceHolderMain_SavePersonalizationButton"));
wait.Until(webDriver => saveButton2.Displayed);
Assert.IsTrue(saveButton2.Displayed);
saveButton2.SendKeys(Keys.Enter);
The while is my JQuery check to make sure nothing is running on the page. Then I added the Assert to make sure that the User Interests header is appearing so that I can be sure it's displayed (although since the text is on the source anyway regardless of which tab displays it passes). The waits were to make sure the elements are appearing on the page, not sure if I need this though. Edit: So my problem comes down to being able to detect the change from:
<div class="RoundedBox Tab inactive" onclick="toggleActiveTab (this, 'ctl00_PlaceHolderMain_PersonalizationTab')">
to
<div class="RoundedBox Tab" onclick="toggleActiveTab(this, 'ctl00_PlaceHolderMain_PersonalizationTab')">
Then I believe this will be resolved.