This is a migrated thread and some comments may be shown as answers.

Find element by Css selector

7 Answers 534 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 03 Aug 2012, 10:26 AM

Hello.

Your framework is very useful but what did you think about find elements by css selector(like WebDriver) or smth like that:

Find.ById("topPanel").Find.ByAttributes("class='buttonPanel'").Find.By.......

<div id="topPanel">
<div class="buttonPanel">
<a>Create New</a>
<a>Import</a>
<a>Create Deploy Configuration</a>
</div>
</div>

7 Answers, 1 is accepted

Sort by
0
Accepted
Cody
Telerik team
answered on 03 Aug 2012, 03:52 PM
Hi,

The problem with using the CSS selector approach is that it's intended to find a set of elements that match some pattern (e.g. all P tags, all DIV tags, etc.). When running web tests you really want to find exactly one specific element to interact with (a button to click on, a text field to enter data into, etc.).

Because of this intended use difference, we didn't see any real value to implementing CSS selectors for finding elements. Instead we created our own Find.Byxxx methods we think are more logical and more natural to the average QA engineer that probably doesn't understand CSS.

Your code sample:
Find.ById("topPanel").Find.ByAttributes("class='buttonPanel'").Find.By.

This is supported today! We call that a "chained find expression". You can also shorten it to this:

Find.ByExpress("id=topPanel", "|", "class='buttonPanel","|",...);

The "|" portion means "and then find" as documented here.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 06 Aug 2012, 11:34 AM
Thanks, It's GREAT!!!
0
Anton
Top achievements
Rank 1
answered on 07 Aug 2012, 10:58 AM

Hm... I try it more time and have problem.

Sometime Expressions doesn't work.

For example:

public static readonly HtmlFindExpression ProjectLabelInProjectsTree = new HtmlFindExpression("id=projectTree", "|", "class=rf-tr-nd-colps", "|", "class=rf-trn-cnt");
Find.ByExpression<HtmlSpan>(MainTestPageObjects.ProjectLabelInProjectsTree).Click();

<div id="projectTree" class="rf-tr">
<div id="projectTree:1st - Projects:j_idt43" class="rf-tr-nd rf-tr-nd-colps firefinder-match">
<div id="j_idt43" class="rf-trn firefinder-match">
<span class="rf-trn-hnd-colps rf-trn-hnd"></span>
<span class="rf-trn-cnt rf-trn-sel">
</div>
</div>
<div id="projectTree:2nd - Deploy Configurations:j_idt52" class="rf-tr-nd rf-tr-nd-lf rf-tr-nd-last">
<div id="j_idt52" class="rf-trn firefinder-match">
<span class="rf-trn-hnd-lf rf-trn-hnd"></span>
<span class="rf-trn-cnt">
</div>
</div>

code return exception - 

          • System.NullReferenceException: Object reference not set to an instance of an object.

0
Cody
Telerik team
answered on 08 Aug 2012, 11:51 PM
Hi,

First you have invalid HTML, you are missing </span> elements at required locations:
<span class="rf-trn-cnt rf-trn-sel"></span>
</div>


<span class="rf-trn-cnt"></span>
</div>

For your Find Expression, all that you missed is that the values for class are more than just "rf-tr-nd-colps" and "rf-trn-cnt". What you had originally was this:
"class=rf-tr-nd-colps", "|", "class=rf-trn-cnt"

Written that way means the value for class must match exactly. Since it only contains that, doesn't match exactly the find wasn't finding a true match. We can change it very easily to indicate 'contains" by preceding the text with a ~ character like this:

HtmlFindExpression ProjectLabelInProjectsTree = new HtmlFindExpression("id=projectTree", "|", "class=~rf-tr-nd-colps", "|", "class=~rf-trn-cnt");

Now it will work.
All the best,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 09 Aug 2012, 07:19 AM
Thanks a lot! It's works.
0
Sakthi
Top achievements
Rank 1
answered on 03 Apr 2018, 03:03 PM

Hi Anton,

I have a one problem inn handling CSS locator. In my code the button id is changing dynamically. So, I have find it with the help of CSS locator using ends with concept "input[id$='_btnManageEffectiveDates']". In telerik I couldn't handle this kind of locator. So, you have any option for this.

0
Elena
Telerik team
answered on 06 Apr 2018, 09:00 AM
Hi Sakthivel,

Thank you for your interest in Progress Testing Framework. 

Please note that css selectors are not yet supported and their implementation is planned for our next official release which is planned for the end of May this year. 

Meanwhile you could use Find expressions to locate elements on page. 

I hope this helps! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Anton
Top achievements
Rank 1
Answers by
Cody
Telerik team
Anton
Top achievements
Rank 1
Sakthi
Top achievements
Rank 1
Elena
Telerik team
Share this question
or