Selenium: how to find div with specific content?

I need to find a <div> with specific content and click from Selenium, since:

  <tr>
   <td> clickAndWait </td>
   <td> // div [@ class = 'gwt-Label' *** WITH CONTENT = 'Logout' ***] </td>
   <td> 5000 </td>
 </tr>

Is there any way to do this? I do not want to use absolute xpath.

+6
html xpath selenium
source share
3 answers

try the following:

  //div[@class='gwt-Label' and contains(., 'Logout')] 
+7
source share

You can also use CSS locators:

 <div class="gwt-Label">This FindMe DIV</div> 

Can be installed using:

 css=.gwt-Label:contains('FindMe') 
+8
source share

Perhaps your XPath is just not quite what you think. You may need to use the string () function to concatenate all the text in a block.

For example, in TestPlan (using Selenium as backend) you would do something like this:

 Click //div[@class='gwt-Label'][contains(string(),'Logout')] 

Note the use of string ()

+1
source share

All Articles