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

Finding elements by content containing  

5 Answers 129 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kovyar
Top achievements
Rank 1
kovyar asked on 19 Aug 2010, 01:27 PM
Hi all.

As we have to support multi-browser automated tests, the tests must run in both IE and Firefox.
After installing the latest build of WebAii we finally can work fine with both of them.
Still I suspect a funny problem with these browsers because they render non-breakable space ( ) in different manner.
Just have a look at this piece of HTML code:

<a href="http://google.com">mega&nbsp;link</a>

Looks usual.

But now, if I want to find this link by the text it contains, troubles appear.

Settings settings = new Settings(BrowserType.InternetExplorer, "d:\\log\\");
Manager manager = new Manager(settings);
 
manager.Start();
 
manager.LaunchNewBrowser();
manager.ActiveBrowser.NavigateTo("http://aspspider.ws/kovyar/find_bycontent_test.htm");
manager.ActiveBrowser.WaitUntilReady();
 
Element element = manager.ActiveBrowser.Find.ByContent("mega link"); //null in both browsers, the desired way to find the element
 
Element element1 = manager.ActiveBrowser.Find.ByContent("mega link".Replace(' ', (char)160)); //null in IE
Element element2 = manager.ActiveBrowser.Find.ByContent("mega link".Replace(" ", "&nbsp;"));  //null in FF
 
Assert.IsNotNull(element1); //here fails IE
Assert.IsNotNull(element2); //here fails FF
 
manager.Dispose();

You can switch the browser type right in the first line of the code.
The general trouble is that I cannot process this link in the same way in FF and IE.
The second problem is that the types of spaces in the text can change (so the appearance of the text would be the same, but spaces would be different).

So we need a way of finding elements on the page which will not depend on:
1) browser type
2) type of spaces used by developers.

It would be really good if there is such a way, because our tests use Find.ByContent very often.

Thanks,
Yaroslav

5 Answers, 1 is accepted

Sort by
0
kovyar
Top achievements
Rank 1
answered on 19 Aug 2010, 01:32 PM
Sorry, your parser has eaten the &nbsp; at the end of the thread name.
0
Accepted
Konstantin Petkov
Telerik team
answered on 19 Aug 2010, 01:42 PM
Hi kovyar,

I see your point and thank you for the details and page!

Have you tried the framework LINQ and lambda expressions support? You can construct an expression to find the element which text content includes all the required words. Is this an acceptable solution for you?

Sincerely yours,
Konstantin Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
kovyar
Top achievements
Rank 1
answered on 19 Aug 2010, 01:53 PM
Hi Konstantin,

and thanks for such a quick reply.
Frankly speaking, I didn't know that such functionality is supported.
Yes, this cool feature completely resolves this problem and one more we had.

Thanks a lot,
Yaroslav
0
joe
Top achievements
Rank 1
answered on 28 Feb 2011, 04:28 AM
is there a way to find by content without it being actual string value but a value within a variable? 
0
Konstantin Petkov
Telerik team
answered on 03 Mar 2011, 10:25 AM
Hi joe,

I don't see a problem doing that. Instead of hardcoded string you just need to pass the object value as argument. Do you experience any problems with that?

All the best,
Konstantin Petkov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
General Discussions
Asked by
kovyar
Top achievements
Rank 1
Answers by
kovyar
Top achievements
Rank 1
Konstantin Petkov
Telerik team
joe
Top achievements
Rank 1
Share this question
or