Find All, Find Next, Find Specific...

Ask general questions here.
Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Find All, Find Next, Find Specific...

Post by Pixi6s » Mon Jul 25, 2011 3:16 pm

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

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

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

Post by sdaly » Mon Jul 25, 2011 3:49 pm

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();
			}

Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

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

Post by Pixi6s » Tue Jul 26, 2011 7:19 pm

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:

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

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

Post by Ciege » Tue Jul 26, 2011 7:30 pm

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.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Wed Jul 27, 2011 8:37 am

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
.
Image