PeterG
PeterG

Reputation: 344

Selenium: Finding if a Webelement is contained inside another Webelement?

I'm currently learning Selenium by building a test framework up to test Trello - for no good reason other than it's free and reasonably complex. The problem I have right now is that, I want to check if a card is in a certain column or not. I have the card & column as WebElements so what I'm doing right now is:

column.FindElements(By.LinkText(_card.Text)).Count > 0;

But this doesn't work if there's no text and seems pretty brittle.

What I want is something like:

column.Contains(_card)

I've searched on SO but I've only seen solutions which pass an XPath - I don't have an XPath, I have the WebElement.

Any ideas?

Upvotes: 0

Views: 192

Answers (2)

Pseudo Sudo
Pseudo Sudo

Reputation: 1412

Using Firefox with the Firebug extension, right click your element and go to Inspect Element with Firebug. Then, when the html of your element comes up in the window, right click the element and select Copy XPath. Now you have an XPath to use.

To use the CSS Selectors that others are talking about, you can select Copy CSS Path instead of Copy XPath.

Hope this helps.

Upvotes: 1

Wes Young
Wes Young

Reputation: 76

Two things,

  1. relative xpath is fairly easy to learn and could probably take care of this for you.

  2. CSS selectors should also easily identify the container regardless of the text. Without seeing the code, I can't help much more.

You should be able to find all elements with a certain css tag.

Upvotes: 1

Related Questions