Page 1 of 1

finding the google search button

Posted: Wed Feb 02, 2011 12:28 pm
by ashishabrol
Hi

I am try to locate the googlesearch button using following lines.

//locate the first DOM and navigate to google
Ranorex.WebDocument doc=Host.Local.FindSingle("/dom[@childIndex='0']");
doc.Navigate("http://www.google.co.in",true,1000);

//Find the google search
//First Way
Ranorex.WebElement ele=doc.FindSingle("input[@Type='submit' and Value='Google Search']");
//Second Way
Ranorex.WebElement ele=doc.FindSingle("//input[@Type='submit' and Value='Google Search']");

ele.PerformClick();

In both cases the code fails because of this:
Ranorex.RxPathException: Parsing RxPath 'input[@Type='submit' and Value='Google Search']' failed:
line 1:25 no viable alternative at input 'Value'

can you tell me what is wrong here?

thanks
Ashish Abrol

Re: finding the google search button

Posted: Wed Feb 02, 2011 12:40 pm
by sdaly
Attributes in the paths must start with @ ;)

Re: finding the google search button

Posted: Wed Feb 02, 2011 1:14 pm
by Support Team
Hi,

as mentioned before the "@" before the attribute "value" is missing.
For more details about the RanoreXPath have a look at following links:
http://www.ranorex.com/blog/ranorexpath-tips-and-tricks
http://www.ranorex.com/support/user-gui ... xpath.html
http://www.ranorex.com/support/screencasts.html

Regards,
Tobias
Support Team

Re: finding the google search button

Posted: Wed Feb 02, 2011 1:16 pm
by ashishabrol
thanks sdaly. very nice! putting an @ before the attribute worked.

one thing more I would like to ask is about the time ranorex takes to locate the googlesearch button. It is quite substantial may be arnd 30sec.

here is the code

Ranorex.WebElement ele=doc.FindSingle("//input[@Type='submit' and @Value='Google Search']");
Ranorex.WebElement textele=doc.FindSingle("//input[@title='Search' and @type='text' and @name='q']");
textele.TagValue="ranorex";
ele.PerformClick();

would you know if the code could be made faster?

thanks
Ashish Abrol

Re: finding the google search button

Posted: Wed Feb 02, 2011 2:09 pm
by Support Team
Hi,

please have a look at the links I've just posted.
Especially RanoreXPath syntax examples which says:
.//button: identifies all buttons that are descendants of the current element, i.e. all buttons in the subtree of the current element
Regards,
Tobias
Support Team

Re: finding the google search button

Posted: Thu Feb 03, 2011 7:55 am
by ashishabrol
Hi

I could not get .// to work. Here is my code.

Ranorex.WebDocument doc=Host.Local.FindSingle("/dom[@childIndex='0' and @BrowserName='IE']");
doc.Navigate("http://www.google.co.in",true,1000);
Ranorex.WebElement ele=doc.FindSingle(".//input[@Type='submit' and @Value='Google Search']");
Ranorex.WebElement textele=doc.FindSingle(".//input[@title='Search' and @type='text' and @name='q']");
textele.TagValue="ranorex";
ele.PerformClick();

error:
Ranorex.ElementNotFoundException: No element found for path './/input[@title='Search' and @type='text' and @name='q']' within 0ms.

Can you advice why this did not work?

thanks
Ashish Abrol

Re: finding the google search button

Posted: Thu Feb 03, 2011 11:50 am
by ashishabrol
I figured that page refresh caused by:

doc.Navigate("http://www.google.co.in",true,1000);

changes the childindex of the webpage(dom). Hence googlesearch button and textbox are never found by me.
If I remove the navigate.doc (above) and run the script on already open google page the script runs fine.

to counter this If I write my script as:

doc.Navigate("http://www.google.co.in",true,1000);
//make sure you are on the top page
Ranorex.WebDocument doc1=Host.Local.FindSingle("/dom[@childIndex='0' and @BrowserName='IE']");
Ranorex.WebElement ele=doc1.FindSingle(".//input[@Type='submit' and @Value='Google Search']");
Ranorex.WebElement textele=doc1.FindSingle(".//input[@title='Google Search' and @type='text' and @name='q']");

even this does not work... :-(

can somone suggest me a solution?

Regards
Ashish Abrol

Re: finding the google search button

Posted: Thu Feb 03, 2011 12:19 pm
by Support Team
Hi,
error:
Ranorex.ElementNotFoundException: No element found for path './/input[@title='Search' and @type='text' and @name='q']' within 0ms.
You have to increase the search timeout for the .FinsSingle method.

So your code should look something like this:
Ranorex.WebDocument doc=Host.Local.FindSingle("/dom[@childIndex='0' and @BrowserName='IE']", 1000);
doc.Navigate("http://www.google.co.in",true,1000);
Ranorex.WebElement ele=doc.FindSingle(".//input[@Type='submit' and @Value='Google Search']", 1000);
Ranorex.WebElement textele=doc.FindSingle(".//input[@title='Search' and @type='text' and @name='q']", 1000);
textele.TagValue="ranorex";
ele.PerformClick();
Regards,
Tobias
Support Team