views:

693

answers:

3

I need to find a <div> with certain content and click it from Selenium, as so:

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

Is there some way to do this? I don't want to use an absolute xpath.

+4  A: 

try this:

 //div[@class='gwt-Label' and contains(., 'Logout')]
krosenvold
Sounds great, but I can't get it to work. Searched for documentation, but found none; do you have a link?
Jonas Byström
http://www.w3.org/TR/xpath/#function-contains
krosenvold
Oh. You need to drop the single quotes around '.'. Edited
krosenvold
Ah, it's XPath, hadn't realized that. Still doesn't work, but hopefully I'll be able to fix it now. Thanks!
Jonas Byström
Selenium identifies the locator, finds the div, but the click never comes through! Any ideas?
Jonas Byström
Are you sure the div is the appropriate target of the click ? The way I remember GWT there's an awful lot of layers
krosenvold
+1  A: 

You could also use CSS locators:

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

Could be located using:

css=.gwt-Label:contains('FindMe')
Dave Hunt
Selenium identifies the locator, finds the div, but the click never comes through! Any ideas?
Jonas Byström
It might be that the DIV isn't the element that responds to the click. Is there a parent/child element that could be more suitable? There are also sometimes issues with `click` and you could try the `mouseDown`, `mouseUp` commands instead.
Dave Hunt
A: 

Perhaps your XPath just isn't quite doing 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()

edA-qa mort-ora-y