I came across some code that looks like this:
get dropdownElement() { return $(`//button[@class='name_here']//span[contains(., 'Dropdown')]`); }
And I’m confused as to what the “//” means here; I know that double backslashes are typically meant to escape a character, but I don’t think I’ve ever seen a double forward slash. Also, when I see back ticks, they’re usually accompanied by “$” so I was wondering about that too.
Advertisement
Answer
This is using XPath syntax to select elements with jQuery. The double slash essentially means “select all descendants that match this selector”.
So //button[@class='name_here']
matches all elements that are buttons with the name_here
class, and //button[@class='name_here']//span[contains(., 'Dropdown')]
matches elements that descendants from those buttons, and are spans, and contain Dropdown
.