Originally posted by TanyaYatskovska on February 27, 2014
Hi Andrey,
There are special methods in TestComplete that allow searching for the target object based on CSS selectors. Refer to the “Finding Web Objects Using CSS Selectors” article for more information.
Originally posted by azakharov on February 28, 2014
Thank you Tanya. It’s a great article but it seems that “:contains” CSS pseudo class is not supported currently. Is there any chance it might be included with the next release? Thanks!
Originally posted by TanyaYatskovska on March 03, 2014
Hi Andrey,
It looks like the W3C Selectors Level 3 specification recommends using the following selector instead of the :contains pseudo-class:
[att*=val]
Represents an element with the att attribute whose value contains at least one instance of the substring “val”. If “val” is the empty string then the selector does not represent anything.
Thanks Tanya! This aproach works almost everytime except for situations when there is no reliable attribute and value to work with.
For example here’s css path to find cell in a table:
html body table.frame_table tbody tr td.frame_body div#divDashBody table.dataGrid tbody tr#row.datacell2 td
The problem is this table is dynamic i.e. what you locate by this css path now might not be the same next minute.
The only reliable way to find cell is to use it’s text content. In other words what this cell :contains. Currently I use xPath text()=‘some text’ locator for this situations but I like locating elements by CSS locators way more