Page 1 of 1

Find All, Find Next, Find Specific...

Posted: Mon Jul 25, 2011 3:16 pm
by Pixi6s
Hi,

I have been trying to get FindSingle or TryFindSingle to work for my situation and it works... sort of.

We have a deal site and the side bar displays all the "additional" deals. Unfortunately our the exact location of these frames to click to get to the deal varies by a DIV or so. I need to click the deals in the side bar.

I can get FindSingle and TryFindSingle to select the first deal but not subseqent deals - even when i drill down.

Code: Select all

WebElement webE = "/dom[@domain='" + Domain + "']/body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]/div[1]/div/div";	
WebElement imgBuy;
bool bFound = webE.TryFindSingle("//img[@alt='Buy']", out imgBuy);
imgBuy.Click();
OR

Code: Select all

WebElement webE = "/dom[@domain='" + Domain + "']/body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]/div[1]/div/div/";	
WebElement imgBuy = webE.FindSingle("//img[@alt='Buy']");
imgBuy.Click();
Those code fragments work for the first deal. I can rely on the first set of DIVs to be the same for each deal so:
deal 1: /body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]/div[1]
deal 2: /body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]/div[2]
deal 3: /body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]/div[3]

Its just the remaining DIVs that vary.

When I try to make the variable webE for deal2 or deal3 it still finds deal1 even though it shouldn't be in that realm.

Code: Select all

WebElement webE = "/dom[@domain='" + Domain + "']/body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]/div[2]/div/div/";	
WebElement imgBuy = webE.FindSingle("//img[@alt='Buy']");
imgBuy.Click();
-- finds deal 1 again

Or if I try to make imgBuy the place where I give the more specific location - this errors out.

Code: Select all

WebElement webE = "/dom[@domain='" + Domain + "']/body/form/div[@id='bd']/div[@id='bd']/div[3]/div[2]";	
WebElement imgBuy = webE.FindSingle("//div[2]/div/div/img[@alt='Buy']");
imgBuy.Click();
Am I not telling it where to look good enough? Is there another Find method that I am missing that would give me a Find All or a Find Specific (say using Index like in vbscript) or Find Next...

Thanks
Sierra

Re: Find All, Find Next, Find Specific...

Posted: Mon Jul 25, 2011 3:49 pm
by sdaly
FindSingle will return the first one found, hence why you only ever get 1... Try something like this...

Code: Select all

IList<Ranorex.DivTag> deals = Host.Local.Find<Ranorex.DivTag>(dealsPath);
			foreach (Ranorex.DivTag deal in deals) {
				Report.Screenshot(deal);
				deal.Click();
			}

Re: Find All, Find Next, Find Specific...

Posted: Tue Jul 26, 2011 7:19 pm
by Pixi6s
Thank you, this pointed me in the right direction.

I would like to point out to anyone else out there that deals.click messes it up. At least in our website when the deal is clicked a new page is rendered so the list created is no longer available (it appears available but its a new 'list').

It was interesting, the second time through Ranorex was defaulting clicking in the upper left hand quadrant, which after 2 clicks up there, it shuts down Ranorex - which was really shocking - 2 clicks on the ranorex logo closes the application - makes prefect since when you walked through it - initally very unfun. :lol:

Re: Find All, Find Next, Find Specific...

Posted: Tue Jul 26, 2011 7:30 pm
by Ciege
I would like to point out to anyone else out there that deals.click messes it up. At least in our website when the deal is clicked a new page is rendered so the list created is no longer available (it appears available but its a new 'list').
This makes sense as the click results in a new page of information, thus the xPaths to the last page of information are all now different.
It was interesting, the second time through Ranorex was defaulting clicking in the upper left hand quadrant, which after 2 clicks up there, it shuts down Ranorex - which was really shocking - 2 clicks on the ranorex logo closes the application - makes prefect since when you walked through it - initally very unfun.
Again, in the end it makes sense... Ranorex is trying to click on an xPath you have provided that no longer exists thus defaulting to the 0,0 coordinates.

Re: Find All, Find Next, Find Specific...

Posted: Wed Jul 27, 2011 8:37 am
by Support Team
Pixi6s wrote:It was interesting, the second time through Ranorex was defaulting clicking in the upper left hand quadrant
That happens if the item is invalid (the Valid property should return false) and the screen rectangle is empty then, thus making Ranorex believe the item is at the very top-left corner of the screen.

Regards,
Alex
Ranorex Team