duncanbrown
15 years agoOccasional Contributor
Variables referring to dynamic web page elements
I'm working on some tests for an ASP.NET website and have come across something I'd be grateful to have some assistance understanding.
On a particular page on the site is a datepicker control (jQuery ui I think), the header of which displays the selected month and year. To get the control's current month and year I set a variable to refer to that header and get its innerText property. The first time I do this, it works fine, but if I then click one of the control's navigation buttons and retrieve the innerText again, I get the original value, not the text that is currently being displayed on screen. Here's an example:
function getDate()
{
var header = Sys.Process("iexplore").Page(urlhere).Panel(1).Panel(0).Form(0).Panel(2).Table(0).Cell(3, 1).Panel(1).Panel(0).Panel(0).Panel(0);
ShowMessage(header.innerText); //September 2011 is shown, as expected
clickNextMonth(); //Screen now shows October 2011
ShowMessage(header.innerText); //September 2011 is shown, still
}
I get the same behavior if I set the header variable to refer to the page element via NameMapping or an Alias, even if I call the variable's RefreshMappingInfo() method before getting the innerText the second time, and adding delays doesn't help.
I have found a few ways to get the correct date to be shown the second time:
If necessary, I will use one of these workarounds, but I'd be interested to know of any better ones. Moreover, it would be helpful to know what is causing this issue in the first place, and it what circumstances one needs to watch out for it.
Thanks in advance for any help.
Duncan
On a particular page on the site is a datepicker control (jQuery ui I think), the header of which displays the selected month and year. To get the control's current month and year I set a variable to refer to that header and get its innerText property. The first time I do this, it works fine, but if I then click one of the control's navigation buttons and retrieve the innerText again, I get the original value, not the text that is currently being displayed on screen. Here's an example:
function getDate()
{
var header = Sys.Process("iexplore").Page(urlhere).Panel(1).Panel(0).Form(0).Panel(2).Table(0).Cell(3, 1).Panel(1).Panel(0).Panel(0).Panel(0);
ShowMessage(header.innerText); //September 2011 is shown, as expected
clickNextMonth(); //Screen now shows October 2011
ShowMessage(header.innerText); //September 2011 is shown, still
}
I get the same behavior if I set the header variable to refer to the page element via NameMapping or an Alias, even if I call the variable's RefreshMappingInfo() method before getting the innerText the second time, and adding delays doesn't help.
I have found a few ways to get the correct date to be shown the second time:
- Don't use a variable at all; refer to the element by the full name (Sys.Process("iexplore").Page....) each time; or
- Call the Page's Refresh() method after changing the date; or
- Insert this after changing the date: header = eval(header.FullName);
If necessary, I will use one of these workarounds, but I'd be interested to know of any better ones. Moreover, it would be helpful to know what is causing this issue in the first place, and it what circumstances one needs to watch out for it.
Thanks in advance for any help.
Duncan