Selecting list values automatically results in StaleElementReferenceException - webdriver

In my search page I have a list with an input box and 'Go' button. I get the list value in my console but what I want is to iterate the list and enter the text (text is static) in the input box. Every time the list is selected it automatically searches rather than having to press the 'Go' button.
WebElement search_list = driver.findElement(By.xpath("//*[#id='tl_tPlace']"));
List <WebElement> li = search_list.findElements(By.tagName("option"));
for(int i =0; i<li.size();i++){
System.out.println(li.get(i).click());
try{
driver.findElement(By.xpath("//*#id='cmain_Place']")).sendKeys("text");
Now the first time the list has "select the state" it passes for the 2nd loop and it selects the list item. Once selected, the page reloads. Then there's an error message:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up

This is entirely expected behavior, since the DOM is completely recreated when the page, so any references you have to elements will become invalid after the page refreshes.

Related

PrismTabbedPage created dynamicly with each tab having its own parameters

I'm setting up a PrismTabbedPage dynamically in Xamarin.Forms. I have a content page PrismContentPageProfile which shows the profile of a given Id. The Id I want to pass with a parameter. Problem is that each initialize is having all the parameters.
await NavigationService.NavigateAsync("NavigationPage/PrismTabbedPage1?createTab=PrismContentPageProfile?Id=Michel&createTab=PrismContentPageProfile?Id=Erik");
I expect to tabs. One for the profileId Michel and one for Erik. Problem is that the paramters in the Initialize look like this on each page:
{?createTab=PrismContentPageProfile%3FId%3DMichel&createTab=PrismContentPageProfile%3FId%3DErik}
As I don't know which tab I am, I don't know which profile to load.
I hoped that calling:
await NavigationService.NavigateAsync("NavigationPage/PrismTabbedPage1?createTab=PrismContentPageProfile?Id=Michel&createTab=PrismContentPageProfile?Id=Erik");
would result in different parameters on each page. Id=Michel on the first page, Id=Erik on the second.
Or, if that is not possible, that I know which tab index I am. Then I can read the related parameter.

ASP.NET DateTime Column in Database Getting Set to Current Date on Page Load

I'm trying to solve an issue where a database column is getting set when navigating to a page in an ASP.NET site. This is a quote management web application, and when opening a quote and navigating to a certain page, the "Expiration Date" is automatically updated to the current date. I have verified that this is occurring prior to triggering the Page_Load function in the ascx.cs file. I have tried to trace what is being run prior to this, but I'm afraid my knowledge of ASP.NET is insufficient, and I don't know exactly where to look. From the pieces I can tell are run prior (for example, the aspx.cs file), I see nothing to indicate any alterations to the record.
When I dig deeper, it seems almost as if the change is taking pace upon leaving the main landing page when editing a quote. If I update the value and travel to any page for the quote except for the main page, it stays the same. And I can travel to the main page, check the record in the database, it stays the same. But it seems like as soon as I navigate from that main page, the Expiration Date will change to the current date. Is there somewhere I can check to see if that's what's happening?
-- EDIT --
Maybe a detail list of actions might help...
View list of quotes in system
Click "Edit" link for quote
View "Quote Details" page, which is first page upon edit access
Look at database query for quote to see exp date is still proper
value
Click "Quote Options" navigation link
See expiration date in "Quote Options" has now changed to current
date
Check database query to see that without performing a known save to
the database the exp date value has updated in the database
Perform update to quote to reset exp date
View any other page in quote edit, return to "Options", see exp
date has not changed again from reset value
Verify proper date with database query
Revisit "Details" page
Again verify correct date with database query
Travel to any other page and then to "Options", or go straight
to "Options", see that exp date has changed to current date
This is the HTML on the link used, which appears to be identical on the other pages...
<a class="tabOff" id="ContentPlaceHolder1_linkButtonAddEditShipping" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$ContentPlaceHolder1$linkButtonAddEditShipping", "", true, "", "", false, true))'>Quote Options</a>
I solved the problem. Sort of. I did discover that the save function was being triggered when leaving the "Details" page, even though no save action was being explicitly activated. The problem was resolved by getting the expiration date from the database at the beginning of the function, and if one was set, pushing that value back in at the very end of the function. While this has in effect prevented the value from being "overwritten", I am still unable to determine why the save function was being triggered, and unable to determine what actions within that function are setting the value to be the current date

Adding Removing Columns to Datagrid in Flex with States

I was developing an app that in the first state you choose a date range using dataFields then you press a button to go to another state and generate a datagrid showing an employee list and another scrollable datagrid with its columns generated dynamically having the worked hours for every employee in every date.
The step sequence to get the error message is:
You choose a date range for example: from 01/01/2013 to 01/31/2013
You press generate button (The app change the currentState = "EmployeeList" and all is OK)
You press the back button (you return to initial state and all is OK)
If you change the date range having more days than before date range then all is OK
If you change the date range having less days than before date range then next error is reached
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.controls.dataGridClasses::DataGridBase/http://www.adobe.com/2006/flex/mx/internal::columnHeaderWordWrap()
at mx.controls.dataGridClasses::DataGridItemRenderer/validateProperties()
at mx.managers::LayoutManager/validateClient()
at mx.controls.dataGridClasses::DataGridHeader/updateDisplayList()
at mx.core::UIComponent/validateDisplayList()
at mx.managers::LayoutManager/validateDisplayList()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
and if you google it then some results take to visit apache bug reporting site
https://issues.apache.org/jira/browse/FLEX-22108
And there is no more...
But I found how to solve it!
To solve it first of all I was googling a lot and i looks like no one got this error and I discover that is a Flex Bug reported to Apache. And I was analyzing the original code from DataGrid.as and DataGridColumn.as to think about a possible solution and I was making some tests and nothing work.
What I did and I hope it will be useful to someone
when you click the back button, inside the backbutton_clickEventLister() and before currentState="";
I just set columns array to new Array();
protected function bttnBack_clickEventHandler(event:Event) : void {
// This code line solved it
dtGrdWorkedHours.columns = new Array();
// Make sure of code it before state change stament
currentState = "";
}

Panel Controls[i] - index out of range

I have a panel Profiles List on a web page. It contains multiple small panels, like a list of items contains lines. The items here are profiles. Each profile is actually a small panel SingleProfile with checkbox inside. Checkbox is the core here, because it has an ID, which is used to find the same items.
On this page there is also another similar big panel. I should add to the second panel only those items, which do not exist in the first one. So, the task is to show in the second panel only those profiles, which are not presented in the first panel. This is checked using IDs of the checkboxes in both lists.
To check if a newly added profile in the second panel already exists in the first panel, I try to access the ID property of each item in the first panel through Controls[] property. I do it in the cycle:
if (ProfilesPanel1.Controls.Count > 0)
{
for (int i = 0; i <= ProfilesPanel1List.Controls.Count - 1; i++)
{
//label1.Text += " "+Convert.ToString(sqlReader["chain_id"]); //Bug #2 - see Stored Procedure description
cbx1 = new CheckBox();
cbx1 = (CheckBox)ProfilesPanel1List.Controls[i].Controls[1]; //Bug #1 - here the Exception occurs
if (cbx1.ID == Convert.ToString(sqlReader["chain_id"])) //if profile already exists in the first panel
{
//Do not add this profile to the second panel
}
}
}
The exception "System.ArgumentOutOfRangeException" occurs in the line marked with "Bug #1".
I use sqlReader which takes IDs from a stored procedure. Stored procedure works fine in the Sql Server. But, when I output values of the sqlReader into a label on a web page (see comments in the code), each value is doubled, like "1 1 2 2 3 3 4 4 5 5".
Solution to BUG #1
Check number of controls and its names from quickwatch in debug mode and see, is ProfilesPanel1List.Controls[i] a panel or some other control. Choose your index correctly after checking it in debug mode.
And also you don't need to use cbx1 = new CheckBox(); line of code. Its next line of code is enough to initialize that Checkbox.
Your sqlReader code is not enough to get the actual cause of 2nd error.
For Bug#1, there is a chance that there might be no nested controls existing underneath 'Controls[i]'. So to guard against the bug, you can first check if there are any nested controls underneath the current element and then checking the type of control before type casting.
if(ProfilesPanel1List.Controls[i].Controls.Count>1 && ProfilesPanel1List.Controls[i].Controls[1] is CheckBox) //Iff you are double sure about layout structure and assured that it is not going to
//change. If changes are anticipated then again doing a foreach(..) over nested 'Controls' and type
//checking is much better.
{
//Do the type conversion etc., as per your requirement.
}
For Bug#2, what do you exactly mean by 'each value is doubled'? As I can see that you are appending to the same Label (with ID: Label1) inside the loop so, there is a chance for the text to be concatenated on every iteration. Also, please be sure as per your requirement, whether you need to manipulate same label's text or label inside nested controls of the parent panel.

What is the most efficient way of filling in details on a web form?

Take a standard web page with lots of text fields, drop downs etc.
What is the most efficient way in webdriver to fill out the values and then verify if the values have been entered correctly.
You only have to test that the values are entered correctly if you have some javascript validation or other magic happening at your input fields. You don't want to test that webdriver/selenium works correctly.
There are various ways, depending if you want to use webdriver or selenium. Here is a potpourri of the stuff I'm using.
Assert.assertEquals("input field must be empty", "", selenium.getValue("name=model.query"));
driver.findElement(By.name("model.query")).sendKeys("Testinput");
//here you have to wait for javascript to finish. E.g wait for a css Class or id to appear
Assert.assertEquals("Testinput", selenium.getValue("name=model.query"));
With webdriver only:
WebElement inputElement = driver.findElement(By.id("input_field_1"));
inputElement.clear();
inputElement.sendKeys("12");
//here you have to wait for javascript to finish. E.g wait for a css Class or id to appear
Assert.assertEquals("12", inputElement.getAttribute("value"));
Hopefully, the results of filling out your form are visible to the user in some manner. So you could think along these BDD-esque lines:
When I create a new movie
Then I should see my movie page
That is, your "new movie" steps would do the field entry & submit. And your "Then" would assert that the movie shows up with your entered data.
element = driver.find_element(:id, "movie_title")
element.send_keys 'The Good, the Bad, the Ugly'
# etc.
driver.find_element(:id, "submit").click
I'm just dabbling in this now, but this is what I came up with so far. It certainly seems more verbose than something like Capybara:
fill_in 'movie_title', :with => 'The Good, the Bad, the Ugly'
Hope this helps.

Resources