7

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.

3 Answers 3

8

You could also use CSS locators:

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

Could be located using:

css=.gwt-Label:contains('FindMe')
Sign up to request clarification or add additional context in comments.

2 Comments

Selenium identifies the locator, finds the div, but the click never comes through! Any ideas?
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.
7

try this:

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

5 Comments

Sounds great, but I can't get it to work. Searched for documentation, but found none; do you have a link?
Oh. You need to drop the single quotes around '.'. Edited
Ah, it's XPath, hadn't realized that. Still doesn't work, but hopefully I'll be able to fix it now. Thanks!
Selenium identifies the locator, finds the div, but the click never comes through! Any ideas?
Are you sure the div is the appropriate target of the click ? The way I remember GWT there's an awful lot of layers
1

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.