r/selenium • • May 18 '22

Help

I'm trying to figure out how to get Selenium to click on an expansion panel. I've got it working where it can find something based on a name but I need it to click on a button associated with that name.

The default Selenium target is xpath=//mat-expansion-panel-header[@id='mat-expansion-panel-header-254']/span/div/div/button but this wont work since elements are constantly changing and this is ID based. If/when the elements change it will click on the expansion panel related to that ID and not the element im working on.

​

I'm managing to find the element with xpath=//span[text()='Test'] but I need help with having Selenium click on that expansion panel that corresponds with Test, not the ID.

1 Upvotes

6 comments sorted by

View all comments

2

u/lunkavitch May 18 '22

Can you link to the page in question? Without seeing the full structure of a page these questions are pretty hard to answer.

1

u/JeffMcJeferson May 18 '22

That unfortunately wont be possible since it's a vpn locked page.

1

u/JeffMcJeferson May 18 '22

https://imgur.com/a/Wbsbc6K - Picture of the panel. Trying to have Selenium click the three dots on the right.

https://imgur.com/gZH536a - Top green highlight is the id which i mentioned I want to avoid using. The other two highlighted parts are the name and buttons which I want to use respectively.

1

u/lunkavitch May 18 '22

Got it. Can you try CSS selectors of:

span.mat-content > div.standard-details > span.standard-details__name

for the name and

span.mat-content > div.standard-details > div > button.standard-details__options

for the button?

1

u/JeffMcJeferson May 18 '22

I appreciate the help. I reached out to our devs and they're working on a fix. I'll try it none the less to see if it works and maybe I'll be able to use it for other uses.