Checking text with Selenium that doesn't appear in the HTML - c#

I need to write a test that checks some fields are updated with the right information when a button is clicked.
The problem is that when the information changes, nothing in the HTML changes.
Is there an alternative to Element.Text to achieve this? As that method doesn't work.
I'm writing my scripts in c# and using Selenium 3.7.0
Steps to automate:
Click a button to draw data from a database and populate fields on the page
Check that these fields now contain the correct data from the database

Start with clicking the element that needs to be clicked to populate your fields. Then you can do something like this:
IWebElement demoDiv = driver.FindElement(By.Id("demo-div"));
string textInElement = demoDiv.GetAttribute("innerHTML"));
.. then use the textInElement variable as you like. What you probably want to do is to make a comparison/assert with your expected value.

I found a solution for this, using Element.GetAttribute("value") returns data within a textbox, whereas I thought it would be looking for the value attribute attached to the element.

Related

How to get my dynamic generated controls value in asp.net C#

I have gone through many articles and similar kind of stack over flow questions. Almost I spend more than a day trying to find the solution, all goes in vain.
First I should tell you what I am trying to make.
There a simple grid having a text box currently
Similar to this article
So when I put some value to text box it generate these text boxes and checkbox within that row.(image related to above description)
There are events firing when text box value get changed , second when add new row is clicked.(Currently ignore delete button event).
What I earlier planned was like this, create controls in every postback,I have saved first row text box values in a viewstate. I create these dynamic controls in grid-row-bound function. So I create no of controls as according to value in viewstate stored value.
I thinked that on event function call I will first store the value of current controls then recreate all controls with same id and put back the value.So problem I am facing is that I can't find my controls on event fire. You can see in these two pic what happening because of that 1st pic 2nd pic.
If you want to see the code , please comment of which sections you want to see the code or full code
Here the link to the code click here

Check if value in controls was changed from the orginal data on button click

I have a page with different controls (checkboxes,textareas, ddls..etc), On pageload the data is loaded into controls.
What would be a good approach to check if the data was modified from the original data after the button was clicked. Using c#.
Thanks,
Hide the default content of controls in HiddenField. Check the last content of controls with comparing the values in hidden fields in ButtonClicked event.
If this is a web application I would look at Session Variables ,ViewState,etc which I personally prefer Session Variables
If this is a Windows I would look at Properties there are a couple of ways you could do it.
can you provide and example as to what type of data you are wanting to hold
sounds like you are looking at creating something like a DELTA
You can inherit from these controls and create custom controls. There you can create property to store your initial value. Later you can compare it to the current value and see if it is changed or not.
Are you doing this to check for concurrency? If so, I would recommend using the entity data model. It has built in features to check if a field has changed from the original. Here is a quick example how to use it:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application
You can use ViewState["Key"]
try with
1. In the load
ViewState["Key"] = texbox.Text;
2. Compare in the post the two values

Custom KeyDown Control

I am very new to ASP.NET and this is my first job and I need to perfom good.
I am stuck on this search page where I have two text boxes. One searches by ID which is int, the second by last name. Both the searched populate a grid view. As per the requirement when the user types in last name and clicks search the grid view should populate which I got working. Now if the user stats typing in the ID Search text box the Lastname Search text box should clear as well as the grid view that had gotten populated should be hidden.
I achieved clearing the text box by using
txtSNumberSearch.Attributes["onKeyDown"] = "clearTextBox(this.id)";
txtSNumberSearch.Attributes.Add("onKeyDown", string.Format("document.getElementById('{0}').innerText='';", txtLastNameSearch.ClientID));
txtLastNameSearch.Attributes.Add("onKeyDown", string.Format("document.getElementById('{0}').innerText='';", txtSNumberSearch.ClientID));
But am not able to clear or hide the grid view on key down in the text box, my boss says I need to create a custom key down event handler. I do not know how to do it. Any help would be appreciated as I really need to perform at this job.
An easy way of hiding the GridView is by simply adding it into a standard div and hiding that.
<div id="divGV">
<asp:GridView>...
</div>
You can hide the div by doing this in javascript:
document.getElementById("divGV").style.display='none';"
You've already got a handler added for txtLastNameSearch, so you could do something like this:
txtLastNameSearch.Attributes.Add("onKeyDown", string.Format("document.getElementById('{0}').value='';
document.getElementById("divGV").style.display='none';", txtSNumberSearch.ClientID));
Text boxes don't use InnerText. Try using value property. Keydown is just fine I think.
Try this.
txtSNumberSearch.Attributes["onKeyDown"] = "clearTextBox(this.id)";
txtSNumberSearch.Attributes.Add("onKeyDown", string.Format("document.getElementById('{0}').value='';", txtLastNameSearch.ClientID));
txtLastNameSearch.Attributes.Add("onKeyDown", string.Format("document.getElementById('{0}').value='';", txtSNumberSearch.ClientID));

list view problem with respect to my problem

I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.

C# Web reportviewer create link to page with id

I have a reportviewer and i want a field to act as a hyperlink. The hyperlink must look like: page.aspx?id=1 But how do i achieve this?
I have entered in the properties window, navigation tab, radio "Jump to URL": page.aspx?id=sum(Field!field.value)
This doens't work :(
What do i have to do to get this work?
Thnx in advance
Martijn
PS: I also have EnableHyperlinks set to true;
Your expression under "Jump to URL" should be:
="page.aspx?id=" & sum(Fields!field.value)
Although I see 2 potential issues with that. First of all, if I remember correctly, the URL must be an absolute path (e.g. http://www.test.com/page.aspx). Secondly, I'm not sure why you're summing on a field. If you mean to only get the "current" value of some field, you don't need the aggregate function, but you have to be sure you are inside a control that repeats data for each row of a dataset, e.g. a detail row of a table.

Categories

Resources