An approach that will work with SproutCore is to use the SproutCore view tree to identify elements rather than by layer ID or class. For example, consider this basic main page,
MyApp.mainPage = SC.Page.create({
mainPane: SC.MainPane.extend({
childViews: ['header', 'mainContent', 'footer'],
header: SC.ToolbarView.extend({
layout: { height: 44 },
childViews: ['headerButton'],
headerButton: SC.ButtonView.extend({
layout: { centerX: 0, centerY: 0, height: 40, width: 100 },
title: "Click Here"
})
}),
mainContent: SC.View.extend({
layout: { top: 44, bottom: 33 },
// etc.
While we don't know the layer ids of these elements beforehand, we do know their parent child relationship in JavaScript. For instance, if I needed certain elements from the page, I'd probably grab them in advance like so,
// Retrieve target views for the current page.
var mainPane = MyApp.mainPage.get('mainPane'),
header = mainPane.get('header'),
headerButton = header.get('headerButton'),
// … etc.
// Then retrieve an element for acting upon.
var buttonLayer = headerButton.get('layer'); // returns a DOM node
// Or retrieve an element id for acting upon.
var buttonLayerId = headerButton.get('layerId'); // returns the auto-generated id
Although I don't have firsthand experience with Selenium, it appears that you can use the execute_script WebDriver instance method to run some simple lookups that return either the element you need or the id of the element you need.
Finally, bear in mind that some views may have dynamically changing children, in particular SC.CollectionView
subclasses like SC.ListView
. In this case, once you target the parent view, you can access the child that you need easily enough using methods particular to that parent view, such as itemViewForContentIndex(idx)
to get item views of a list.