0

The HTML is as follows:

<div class="item link-color-1 
     automated link-track logout-link" 
     data-track-category="Logout" 
     data-track-action="Logout from /myaccount/mymoney/cashier" 
     data-data-automated-function="clickTracker"> logout </div>

To find the x path of a link, tried something like: //*[contains(@data-track-category='Logout']. But its not working. Please help.

1
  • Do you really need to use Regular Expressions? I've posted an answer, not sure it will help since i can't see what language you need this.
    – aimbire
    Commented May 7, 2013 at 19:39

2 Answers 2

1

If you are just trying to find the element itself (and not the value of the attribute as your question title implies), you could always use CSS (its my selector of choice over XPath).

You have not indicated which language bindings you use, so this is how I would find it in Ruby by using only the data-track-category attribute to select the element:

@driver.find_element(:css => "[data-track-category='Logout']")

Of course, the same applies across all the bindings. Just use the value "[data-track-category='Logout']" for your CSS method.

0

You can always store the given element in a WebElement and then using the getAttribute() method. You can find the documentation here

WebElement myDiv = driver.findElement(By.className("logout-link"));
String attributeValue = myDiv.getAttribute("data-track-category");

This should work on Java. Not sure that's the language you are looking for or if you must use regex for it.

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.