0

I am using Selenium webdriver with java.

I am trying to find elements in drop down lists, can`t access it by exact id/name/xpath because those are dynamic elements, so I tried to locate it by relative xpath, and it works but not fully, please see image below:

IMAGE ON IMGUR (CANT POST IMAGES YES)

As you can see on top left, there is a drop down overlay with 3 options, ALL/ACTIVE/INACTIVE, now I managed to locate all 3 of them by using relative xpath as shown on image:

//*[@class="cdk-overlay-pane"]//*[@class="mat-option-text"]

But how to now get one element (out of 3 in this case) that got specific text, for example "Active" ? I tried following:

//*[@class="cdk-overlay-pane"]//*[@class="mat-option-text"]//*[contains(text(),'Active')]

But it does not find anything, any help would be welcome!

2 Answers 2

1

Found a solution, search for text using "contains"

Here`s working relative xpath in my case:

//*[@class="cdk-overlay-pane"]//*[contains(text(), 'All')]

It would return element with "All" text that is located within drop down panel.

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

1 Comment

just for info, if you have 2 texts: 'All' 'All active', you will match 2 elements. Better to do equals of string, just to normalize the white space.
0

Try with

//*[@class="cdk-overlay-pane"]//span[@class="mat-option-text" and normalize-space(text())="All"]

1 Comment

Indeed it is much better solution, I used contains, because of the white spaces (did not realise I could remove it the way you did, thank you)

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.