1

In a webpage that I want to automate, getting few results with a class search as below for Css.

.all_message-min_text

The matching node results that I got are, currently, only 2 as below.

<div class="all_message-min_text all_message-min_text-3">User Login Reset</div>

<div class="all_message-min_text all_message-min_text-3">Ali Testing Questions</div>

So when trying to use a Css locator with innertext ('User Login Reset') as below,

div:contains("User Login Reset") 

I am not getting any results. So how to use a correct css selector here to return a unique node only ?

Here is the Html code of the required web page area:

<div class="all_message-min">
<div id="check_1508091097-2000275591-emailuser6" class="all_message-min-
check-container" onclick="checkBox('1508091097-2000275591-
emailuser6');if(event.stopPropagation)
{event.stopPropagation();}event.cancelBubble=true;">
<div class="all_message-min_autor ng-binding" style="display:none" 
title="TO"/>
<div class="all_message-min_autor ng-binding" title="FROM">Dammarie F</div>
<div class="all_message-min_text all_message-min_text-3">User Login 
Reset</div>
<div class="all_message-min_datte all_message-min_datte-3 ng-binding">about 
19 hours ago</div>
</div>
</li>
<li id="row_1508091052-1000275652-emailuser6" class="all_message-item 
all_message-item-parent cf ng-scope" ng-repeat="email in emails" 
onclick="showTheMessage('1508091052-1000275652-emailuser6');">
<div class="all_message-min">
<div id="check_1508091052-1000275652-emailuser6" class="all_message-min-
check-container" onclick="checkBox('1508091052-1000275652-
emailuser6');if(event.stopPropagation)
{event.stopPropagation();}event.cancelBubble=true;">
<div class="all_message-min_autor ng-binding" style="display:none" 
title="TO"/>
<div class="all_message-min_autor ng-binding" title="FROM">Dammarie F</div>
<div class="all_message-min_text all_message-min_text-3">Ali Testing 
Questions</div>
<div class="all_message-min_datte all_message-min_datte-3 ng-binding">about 
19 hours ago</div>

Tried in Firefox v 55.0.2 and chrome latest. Also I've tried using node.textContent as below but it did't seem to work.

div[textContent='User Login Reset']
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Vizag
  • 375
  • 2
  • 6
  • 22
  • 1
    Try to locate by XPath `//div[.="User Login Reset"]` – Andersson Oct 16 '17 at 13:50
  • 1
    As far as I know, the ability to use css selectors to identify nodes by text has been removed quite a long time ago for performance reasons. Whenever I need to find something by text, I use **xpath** instead. – mrfreester Oct 16 '17 at 14:23
  • Ok will use Xpath. I 've wanted to use Css in first place because that seems to be quick while running the automation tests across different browsers. But thank you for responding, Andersson and mrfreester. – Vizag Oct 16 '17 at 14:44
  • If you can format the `HTML` as per your exact `HTML DOM` I can help you to derive a `css` – undetected Selenium Oct 16 '17 at 14:54
  • Please take a look at the [Is there a CSS selector for elements containing certain text?](https://stackoverflow.com/questions/1520429/is-there-a-css-selector-for-elements-containing-certain-text) – dey.shin Oct 16 '17 at 14:58

0 Answers0