0

How do i find the CSS locator to find the text "26 Todman Ave Kensington"

When I do dd:class='.pickup.ng-binding' I get the above along with the line below which contains date and time.

I need to get only Line 1enter image description here

6
  • 1
    Do you mean "selector," rather than "locator"? And why is this tagged as java? Commented Feb 16, 2015 at 3:38
  • You may be looking for the non-existent contains or has pseudo-classes. Commented Feb 16, 2015 at 3:54
  • What is the meaning of the syntax dd:class='.pickup.ng-binding'? It's a syntax error and will select nothing at all. Commented Feb 16, 2015 at 3:55
  • Not directly related to your question, but it could be useful to learn correct terminology. CSS does not have "locators", it has "selectors". Commented Feb 16, 2015 at 4:30
  • @Justin Lardinois: Probably because OP is using Java with Selenium WebDriver, which for some reason they completely neglected to mention directly in this question. Looking at their profile, their activity in the Selenium tags seems to confirm this. Commented Feb 16, 2015 at 4:37

3 Answers 3

1

According to your markup (and if I understand you correctly), this is the selector that you would need:

.pickup.ng-binding > i:first-of-type

Right now, you're selecting everything in .pickup.ng-binding'. What you appear to want is to use the attribute first-of-type to get the first i, which is in this case 26 Todman Ave Kensington.

Edit: I just saw that "26 Todman Ave Kensington" is not wrapped in the i class="fa fa-map-marker. Now your question has rendered me utterly confused.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you could try to wrap the first line with a <p>tag. So you could select them by using .pickup.ng-binding > p

2 Comments

Or you could add a <div id="this-is-the-todman-ave-address'> element around it and style using the selector #this-is-the-todman-ave-address.
Code cannot be changed. we need to find a way to write a selector.
0

You're trying to get one of the child text nodes inside dd.pickup.ng-binding, which is not in an i element but directly in the dd element. This cannot be achieved directly using just a CSS selector since selectors only look at element nodes, not text nodes. You could just select the dd itself like you have done, but you will need to getText() and then parse it and extract just the portion you need, which is cumbersome.

I recommend using XPath instead which allows you to select individual text nodes directly without having to worry about parsing what might be arbitrary text:

driver.findElement(By.xpath("//dd[@class='pickup ng-binding']/text()[1]"));

Depending on what the actual markup looks like (what you have is a DOM tree view), if text()[1] doesn't get you anything it's probably inter-element whitespace; try text()[2] and so on until you find the text that you need.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.