
I have a webpage with a list of elements. I want to select a button side of the div that is listed down the page, where the parent div contains an element with a specific value.
For example in the screenshot below, I'm looking for the Edit button, that shares a parent with an element with the title "Research Seminar".
The position in the list can vary a lot, so indexes are not going to work I think. Any ideas?
Ok, I've worked it out. The trick was to use ":has()
First I got the selectors for the 3 elements I was looking at
div[Id="AgreementReviewListSection_RDP_ThumbnailViewer_CARD"] > div > div > div > div[Class="itemWrapper clearFix"] //the shared parent
div[Id="AgreementReviewListSection_RDP_ThumbnailViewer_CARD"] > div > div > div > div > div > div > div > ul > li > button[Title="Edit"]:eq(2)//the title (condition)
div[Id="AgreementReviewListSection_RDP_ThumbnailViewer_CARD"] > div > div > div > div > div > div > div > div[Title="Research Proposal"] > span[Text="Research Proposal"] //the button (goal)
and combined them to look for the button, under the parent that has the selector
div[Id="AgreementReviewListSection_RDP_ThumbnailViewer_CARD"] > div > div > div > div[Class="itemWrapper clearFix"]:has([Title="Research Proposal"]) > div > div > div > ul > li > button[Title="Edit"]:eq(2)
I'm still pretty new at this, so any feedback on how this could be done easier, or cleaner would be appreciated