finding the google search button

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

finding the google search button

Post by ashishabrol » Wed Feb 02, 2011 12:28 pm

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

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

Re: finding the google search button

Post by sdaly » Wed Feb 02, 2011 12:40 pm

Attributes in the paths must start with @ ;)

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

Re: finding the google search button

Post by Support Team » Wed Feb 02, 2011 1:14 pm

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

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: finding the google search button

Post by ashishabrol » Wed Feb 02, 2011 1:16 pm

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

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

Re: finding the google search button

Post by Support Team » Wed Feb 02, 2011 2:09 pm

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

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: finding the google search button

Post by ashishabrol » Thu Feb 03, 2011 7:55 am

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

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: finding the google search button

Post by ashishabrol » Thu Feb 03, 2011 11:50 am

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

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

Re: finding the google search button

Post by Support Team » Thu Feb 03, 2011 12:19 pm

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