Refer to Ranorex repository elements dynamically - c#

I have the following issue.
I'd like to refer to some repository elements dynamically.
For example, I have a button. Let's say it is a delete button.
It's name is constructed like this:
suppose I want to delete an element called "Joe"
In this case the delete button is called in Spy:
Joe.DeleteButton
In case of Bill, it is called
Bill.DeleteButton
If I want to implement a click on it I'd like to use a statement like this:
repo.Joe.DeleteButton.Cklick();
repo.Bill.DeleteButton.Cklick();
But the name is determined during runtime.
Can I set, construct this repo...  statement dynamically or is there a way to refer to it dynamically (during runtime)?

If Joe and Bill have identical type and located on some repo container you can find them like this
Ranorex.Adapter namesContainer = repo.NamesContainer.Self;
List<*Names_Type*> namesList = namesContainer.FindChildren<*Names_Type*>();
after that, each name can be clicked in that way
namesList[1].DeleteButton.Click();

For me to give a complete answer, I would need to know the XPath of both the delete buttons.
For example, if Joe and Bill are both forms and they both contain the delete button, the XPath syntax of the repo items could be something like this:
Joe Delete button = /form[#title='Joe']/button[#accessiblename='Delete']
Bill Delete button = /form[#title='Bill']/button[#accessiblename='Delete']
If you only wan't to click the delete button, regardless of the form name, simply change the XPath syntax to this:
Any Delete button = /form/button[#accessiblename='Delete']
You could add #processname to ensure it is the delete button of your app, or use anything else unique to your app under test.
In your particular issue, the Ranorex Spy is your best friend.
If you wan't to know more about XPath, I recommened watching Ranorex screencasts (really worth your time):
Ranorex Screen casts
There is also valuable information about XPaths in the following article:
Ranorex XPath tips and tricks
Hope this helps!

Related

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

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.

c# - search listview items using textbox

I am working on a project (simple phone book) for personal use.
Here you can take a look how it looks like:
IMAGE: http://s24.postimg.org/3qlicrcdx/Kruzeri.png
I am just about to finish it, but first I have to configure search bar to work properly. I would like it to find the contact I have entered in the textBox7. Ideally, first of all I would have to enter contact's name and then press the search button located right by the textbox. Then, it should select the contact I was searching for.
I have tried to solve this in numerous ways but with no success.
Does anyone have any idea how can I do this?
If needed, I have uploaded the whole code here where you can take a look at it:
LINK: http://www.sendspace.com/file/qa8rnq
If you use binding to fill your listbox, then you can just filter your list. For example:
element.ItemsSource = contactlist.Where(x => x.Name.Contains("SearchName")).
Have you read on regular expressions (RegEx)? That way you wouldn't need to write the exact name.
Plus, you should start naming your controls properly. Instead of textBox7, name it something like txtSearch. Using the prefix for the control "type".
Button: btnDoStuff
Textbox: txtDoStuff
etc..

How To Implement Search Option To DataGridView?

Lasttime my question may not be clear.So I comeback with same clarification to get the answer.
I develop one small Windows Application.
In C# coding time while I press Ctrl+F then I can able to see Find Window.
Similarly I want to have a serch to my DataGridView, and its DataSource is MyTable1. When the user presses Ctrl+F then I would like to do search and locate on Particular Row-Column in DGV's DataSource column.
Is it possible? Or any other way?
Thanks For Ideas
Here's a link with a simple sample of DataGrid search and highlight.
the data table has a defualtview property, you can use the filter property to apply the search. its like sql but only with the part that comes after the where

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.

Find as you type in C#

Im trying to emulate a 'find as you type' function like that of the address bar ("awesome bar") in FireFox. I want a suggestion box to appear below a textbox, and the suggestion box contains strings that contain what is in the textbox. I looked at the autocomplete feature of a normal WinForms textbox, but it seems to only search the beginning of the strings.
Has anyone here built or have experience with implementing something like this?
edit:
Some clarification- It is a WinForms project.
It needs to search inside a string, not just the beginning (which is what a normal textbox does if i recall correctly). And the suggestions should be displayed in a popup like a textbox autocomplete.
You need to handle the TextChanged event for your text entry field, and when the text changes, start a new thread running that will apply the new search. If the text changes before you get your results back, just kill the thread. If the thread returns results in time, display them.
You can get slightly more advanced (e.g. wait for a short time after the text changes so that the user can type a word without you triggering off loads of useless threads) but essentially that's it.
There was a discussion earlier on this topic where the author concluded that you are better off doing the whole thing yourself.
How can I dynamically change auto complete entries in a C# combobox or textbox?
I did something vaguely similar, but more like the iTunes® search box than the Awesomebar. My control used the textbox to actively filter a grid; so it wasn't for autocompletion.
...but... basically I had a DataView of all eligible items, whenever the TextBox's Text changed I'd update the Filter to hide all non-matching items. It worked well and might suit your needs for filtering the data--but not sure how to go about using it as an AutoComplete source for the textbox.
I have done such a thing for an app of mine not too much time ago.
What I did is make my search function in a new thread, so every time I typed a new letter, it called the search function in another thread, so I could keep on typing.
I can post some code if you need, but this should be enough to get you started. :)
Hemmed and hawed about deleting this after I noticed the OP edit mentioned winforms, but I think it'll be useful to anyone who comes here looking for the same but for asp.net apps.
Just because nobody has mentioned it yet, for a webforms app you absolutely want to do this with ajax (.net controls or pure JS, your choice). The feature is often called "autocomplete" and the one thing you don't want it to be breaking the seamlessness by making server round trips at the page level.
I suggest you look at this and this.
I've used Search As You Type in C# and How do I make a Textbox Postback on KeyUp?
Basically you use the keyup action to call a postback thats attached to the trigger to the update panel. then you do your update in the textbox_changed event with the dataview or whatever your backend looks like.

Categories

Resources