1

We have a HTML Angular Material Accordian.

When its Toggle Expanded, it has class mat-expanded.

<mat-expansion-panel _ngcontent-ng-cli-universal-c931="" 
 data-qa="product" 
 class="mat-expansion-panel ng-tns-c515-10 ng-star-inserted mat-expanded">

When Accordian is Collapsed, Mat-Expanded Goes away, disappears.

<mat-expansion-panel _ngcontent-ng-cli-universal-c931="" 
  data-qa="product" 
  class="mat-expansion-panel ng-tns-c515-10 ng-star-inserted">

We are trying to write IsAccordianExpanded boolean method, how can this be done?

We want to locate element by data-qa attribute "product" as locator.

https://material.angular.io/components/expansion/overview

Resource:

Javascript: Select all data-qa attributes on HTML Page

1 Answers1

1

select the webelement, and then use the getAttribute. You can then check the string to see if it contains the value:

In java:

    String classValue = driver.findElement(By.xpath("//*[@data-qa='product']")).getAttribute("class");
    classValue.contains("mat-expanded");
DMart
  • 2,401
  • 1
  • 14
  • 19
  • hi, accepted answer and gave points, maybe you can help answer this question? https://stackoverflow.com/questions/64585817/javascript-selector-find-checkbox-for-corresponding-sibling-text –  Oct 29 '20 at 14:20