Sandeep Dhamale
Sandeep Dhamale

Reputation: 489

Find element by XPath with attribute name within square brackets

I need to build a XPath with attributes within square brackets. This is from Power BI report:

HTML Element:

<exploration-container [view-model]="viewModel.explorationContainer" [exploration-container-options]="explorationContainerOptions" ng-version="8.2.6">

Tried following but did not work:

//exploration-container[@[exploration-container-options]='explorationContainerOptions']

Upvotes: 1

Views: 761

Answers (2)

Guy
Guy

Reputation: 50819

You can do it using name() to work with the attribute name

Direct match

//exploration-container[@*[name()='[exploration-container-options]']='explorationContainerOptions']

Contains

//exploration-container[@*[contains(name(), exploration-container-options)]='explorationContainerOptions']

Upvotes: 3

Amruta
Amruta

Reputation: 1166

Use CSS if possible. Just a simple \ before [ for example

//exploration-container[\[exploration-container-options]='explorationContainerOptions']

Hope this might help you.

Upvotes: 2

Related Questions