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

Select Element by class values

11 Answers 287 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Martin Kulov
Top achievements
Rank 2
Martin Kulov asked on 17 Jul 2017, 07:40 PM

Hi,

Is it possible to define CSS selector for defining elements in Test Studio/Elements?

I would like to select a html element based on more complex class values.

 

Thank you!

 

 

11 Answers, 1 is accepted

Sort by
0
Nikolay Petrov
Telerik team
answered on 20 Jul 2017, 12:21 PM
Hello Martin,

Thank you for your question.

Unfortunately such feature as CSS selectors is not available at the current state of the product.

If there is a need to - automatically generated find logic of an element could be adjusted to wok properly using for example a chained expressions or using proper find expression statement. 

I hope this answers to your question.

Kind Regards,
Nikolay Petrov
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Martin Kulov
Top achievements
Rank 2
answered on 20 Jul 2017, 08:52 PM

Hi,

What would be the best way to find controls in frameworks like EmberJS where HTML elements have dynamically changing IDs?

So far I have identified CSS selectors to be one good option.

Can chained expressions or find expression statement going to work?

 

Thanks!

0
Elena
Telerik team
answered on 25 Jul 2017, 03:15 PM
Hello Martin,

Test Studio find expression is quite powerful even when the html elements has dynamic ids. This is because you could include any properties in the find expression to get a set of unique and static attributes to identify an element. 

I am not sure if you are using only the Testing Framework or the full product but here are some further details about find expressions in code. 

In case you would need any further assistance please share some specifics of the issue you are facing so that we could investigate the exact scenario.

Thanks in advance for your understanding! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Martin Kulov
Top achievements
Rank 2
answered on 26 Jul 2017, 09:20 AM

Dear Elena,

I would like to search for an element defined by CSS selector like this:

#myid div.class1.class2 div.class3.class4 div.class5

 

This is the Selenium statement I am using right now:

driver.FindElementByCssSelector("#myid div.class1.class2 div.class3.class4 div.class5");

 

Can I do something similar with Test Studio?

 

Thank you

 

 

 

0
Elena
Telerik team
answered on 28 Jul 2017, 01:58 PM
Hi Martin,

Thank you for sharing your ideas.

Though it is important to note that Test Studio is not supporting CSS selector so these could not be applied like you could in Selenium. 

On the other hand Test Studio is using an intelligent element identification scheme which could be even more powerful than css selectors. Even if the elements have dynamic ids they probably could be identified by some of their other attributes and properties or a set of these which point to a unique element on page. Probably you could rely on text content, for example. 

The chained find expression could be applicable and useful depending on the structure of the web page under test. In most cases there is a parent element which could be identified by a unique attribute among the rest elements and then could be used to narrow down the amount among which the required one should be identified. 

If the above information does not provide sufficient information to accomplish your goals you could probably provide a sample application along with a scenario in which you are facing difficulties. This will be the easiest way to provide exact directions. 

Thank you in advance for the cooperation! I am looking forward to hearing from you in case of any further queries. 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Martin Kulov
Top achievements
Rank 2
answered on 30 Jul 2017, 10:42 PM

Hi Elena,

 

It is not clear to me can I use intelligent element identification to select an item based on class values of its parent elements like in the css selector example below:

#myid div.class1.class2 div.class3.class4 div.class5

 

Do you have some similar functionality that I can use to select the same element that will get selected from the css selector example above?

I understand that you do not support css selector syntax now.

Do you have similar functionality that will help me select the same element based on css values of the element itself with combination of its parents?

 

Thank you,

Martin Kulov

 

 

 

 

0
Elena
Telerik team
answered on 02 Aug 2017, 01:39 PM
Hi Martin,

Thanks for getting back to me. 

Since css selectors are not supported you would not be able to rely on these to identify an element. Though you could use chained find expression in order to locate an element using attributes of both its parent element and the target element itself. 

In case there is a certain difficulty you are facing you might want to share a sample application along with a test related to it. That way I will be able to provide more direct advice. 

Thanks in advance for your understanding! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Martin Kulov
Top achievements
Rank 2
answered on 02 Aug 2017, 01:56 PM

Hi Elena,

As explained already, I have the following nested elements and corresponding attributes

 

element 1 id - #myid

element 2 type div style="class1 class2"

element 3 type div style="class3 class4" 

element 4 type div style="class5"

 

How can I use chained find expression to find element 4 based on the attributes of all its parent elements and itself?

 

Thank you!

 

 

 

0
Accepted
Ivaylo
Telerik team
answered on 07 Aug 2017, 12:36 PM
Hello Martin,

Let me interject into this ticket as Elena is out of the office.

The closest Test Studio functionality of CSS selectors is using XPath in your find logic. Your find logic should look something like this:

//div[@id='myid']/div[@style='class1 class2']/div[@style='class3 class4']/div[@style='class5']

This is the complete relative XPath that you might be using.
If the element you are looking for has unique attribute you can use simply:

//div[@id='anotherdiv']

Hope this helps.

Regards,
Ivaylo
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Martin Kulov
Top achievements
Rank 2
answered on 08 Aug 2017, 06:36 PM

Thank you, Ivaylo!

 

0
Ivaylo
Telerik team
answered on 09 Aug 2017, 08:32 AM
Hello Martin,

You are most welcome.

I have added a feature request, about adding CSS selectors in Test Studio's find logic. You can review the item and vote for it using this public link.

Regards,
Ivaylo
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Martin Kulov
Top achievements
Rank 2
Answers by
Nikolay Petrov
Telerik team
Martin Kulov
Top achievements
Rank 2
Elena
Telerik team
Ivaylo
Telerik team
Share this question
or