WaitForNotExists on type Element

Best practices, code snippets for common functionality, examples, and guidelines.
haniball
Posts: 13
Joined: Fri Sep 18, 2015 2:27 pm

WaitForNotExists on type Element

Post by haniball » Tue Apr 26, 2016 9:49 am

I have code that finds elements with the Find() option. With find you get an element of certain type e.g. Ranorex.Text but not the Info element. It seems you can't get the RepoItemInfo from the element (which seems legit because it has nothing todo with the repo). But for example WaitForNotExists() is an extension method for RepoItemInfo.

I found that if I say:
Ranorex.Text mySearchResultItem = Host.Local.Find("//text['myText']") and then
mySearchResultItem.GetPath() I do not get a good path I get '....//text[2]' instead of '....//text['myText']' in certain cases

My scenario is just find an element by value, remember it in a variable, delete the item and wait until deleted and I for many reasons want to do this with the Find() method.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: WaitForNotExists on type Element

Post by odklizec » Wed Apr 27, 2016 8:45 am

Hi,

Because WaitForExists/NotExists is applicable to repoinfo object, you will have to use something else to detect notexistence of an object. I would suggest to use 'while' loop and TryFindSingle method, which returns true/false if element found/not found.

Code: Select all

string xpath = "your xpath";
var foundElement = null; 
bool exists = Host.Local.TryFindSingle(xpath, 5000, foundElement);
while (exists)
{
    Delay.Duration(500);
    exists = Host.Local.TryFindSingle(xpath, 5000, foundElement);
}
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

haniball
Posts: 13
Joined: Fri Sep 18, 2015 2:27 pm

Re: WaitForNotExists on type Element

Post by haniball » Mon May 02, 2016 1:28 pm

Thanks for your answer. That's what I thought too but I have as mentioned the problem that the path is not good if I say Find() and then .GetPath()
I found that if I say:
Ranorex.Text mySearchResultItem = Host.Local.Find("//text['myText']") and then
mySearchResultItem.GetPath() I do not get a good path I get '....//text[2]' instead of '....//text['myText']' in certain cases
Example: I delete the second of three items and the path is found with ..../text[2] it doesn't recognize that the element is deleted because text[2] exists (former element three that became element two).

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: WaitForNotExists on type Element

Post by odklizec » Mon May 02, 2016 1:47 pm

Hi,

I'm afraid, I'm not getting it. Let's say you trying to delete a Text item at path //text[@innertext='myText'] so why do you care/want to use GetPath if you already defined an xpath in Find method?

If you check my example, there is no GetPath used, yet it should help you to wait for not-existence of a deleted element.

BTW, could you please post a Ranorex snapshot of your app before and after the delete action?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

haniball
Posts: 13
Joined: Fri Sep 18, 2015 2:27 pm

Re: WaitForNotExists on type Element

Post by haniball » Tue May 03, 2016 2:05 pm

Mhmm well I don't really say Find() on //text[@innertext='myText']. I just say ....//text to get child elements of a container with multiple results and save the results to a list. Then I get a special item from the list usally by TextValue and do something with it. So I never really have the path to that item except if I say GetPath() which sometimes gives me something like ...//text[2].

Its a bit more complicated than that because I have text items and listitems in that list.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: WaitForNotExists on type Element

Post by odklizec » Wed May 04, 2016 7:16 am

Hi,

Well, in your first post, you mentioned the use of Find method and then GetPath method? I still think there is no need to use GetPath after using Find, but I may as well misunderstand your goal or implementation problems you are facing ;)

Anyway, the reason why GetPath returns something like //text[2] is, that there is most probably no better attribute to return from the text element?

As I mentioned before, please upload a Ranorex snapshot of the problematic list so we can check what attributes are available for the Text items within the list. It may be possible, that instead of Text, it would be better to obtain a path from an ancestor? Eventually, you may need to adapt the Ranorex xpath weight, so it would return better results? There may be several solutions of your problem, but you see, it's quite hard to suggest something reliable without sample app (HTML code) or at least a Ranorex snapshot.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration