ingo
ingo

Reputation: 856

Selector definition with Testcafe

I build up some tests with a selector

.click(Selector('div').withText('19233456').nth(9).find('.np-folder-fave'))

Works well. But in some situations it is possible that there is also a test folder 192334567. So I tried to get a more saved method to select the item, but it is not possible. I tried:

.click(Selector('div').withExactText('19233456').nth(9).find('.np-folder-fave'))

But this will fail. I tried a very saved way:

.click(Selector('div').withAttribute('title', '19233456').find('.np-folder-fave'))

Do not work. Only in the first case the item is selected/clicked. The element in the page is:

<div class="np-folder" style="background-color: rgb(255, 255, 255);">
<div class="np-folder-name" title="19233456">19233456</div>
<div class="np-folder-fave"></div>
</div>

The div fave will cause a popup menu. Why it is not possible to click a selector with the exact text in this case?

Upvotes: 2

Views: 168

Answers (1)

aleks-pro
aleks-pro

Reputation: 1669

The find method searches among descendants of elements in the matching set. The np-folder-fave div is not a descendant but a sibling of the np-folder-name div. So the same Selector with the sibling method should work:

Selector('div').withAttribute('title', '19233456').sibling('.np-folder-fave')

Upvotes: 2

Related Questions