Launch Google Chrome and access it's DOM elements

Class library usage, coding and language questions.
johndoe777
Posts: 1
Joined: Sun Aug 11, 2013 2:04 pm

Launch Google Chrome and access it's DOM elements

Post by johndoe777 » Sun Aug 11, 2013 2:11 pm

Hi,

I'm trying to automate a webpage using code.
I've tried to use "Record & Play", but it didn't work well for me, because this website is using different ids for each session.

This is the code I'm trying to imitate:
pseudo code:

Code: Select all

var document = OpenBrowser("cnn.com", "chrome");
var elements = document.getElementsByTagName("input");
in Ranorex, I've used the following:

Code: Select all

int procssID = Host.Local.OpenBrowser("cnn.com", "chrome", "", false, false);
But now, I dont know how to get access to the DOM elements of the process of chrome.
When I tried to use:

Code: Select all

Host.Local.Find<WebDocument>("/dom");
I've received objects of "IE", and _NOT_ of the "chrome.exe" process I have launched.

Is there any way at all to do it ?
Thanks for any help.

Regards,
JD.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Launch Google Chrome and access it's DOM elements

Post by Support Team » Tue Aug 13, 2013 4:42 pm

Hello,

Some webpages uses 'Dynamic IDs' which make it difficult for Test Automation.
We have posted a blog that describes this issue and presents a solution:
http://www.ranorex.com/blog/automated-t ... ynamic-ids

It looks like that the DOM object of Chrome is not fully loaded when you try to access it.
Please try to add a Validate.Exists() before:

Code: Select all

Validate.Exists("/dom[@domain='edition.cnn.com']");
Alternatively, you could use WaitForDocumentLoaded():

Code: Select all

WebDocument webDoc = @"/dom[@domain='edition.cnn.com']";
webDoc.WaitForDocumentLoaded();
Regards,
Markus (T)