Maalamaal
Maalamaal

Reputation: 973

CSS element locator

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

Upvotes: 0

Views: 190

Answers (3)

BoltClock
BoltClock

Reputation: 723428

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.

Upvotes: 0

seanlevan
seanlevan

Reputation: 1415

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.

Upvotes: 1

Linghanmin Liu
Linghanmin Liu

Reputation: 76

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

Upvotes: 0

Related Questions