Greasemonkey Click Button without ID or Name

Viewed 99

I'm trying to autoclick this button with greasemonkey. I tried to find a reference to this button with document.getElementsBy[ClassName/Name/TagName] with ClassName i find buttons but not the one i need. Any ideas how i can automate his click-event?

<button type="button" class="ml-2 mt-2 v-btn v-btn--depressed theme--light v-size--default amber darken-1 white--text ">
    ::before
    <span class="v-btn__content">
        <!----> 
        Überspringen
        <i aria-hidden="true" class="v-icon notranslate v-icon--right material-icons theme--light">
            redo
            ::after
        </i>
        <!---->
    </span>
</button>

Screenshot from Firefox Inspector with Click Function

Thanks in Advance!

1 Answers

Just use xpath for element searching:

document.evaluate(XPATH, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

  1. You can use class parameter instead id or name:
  • xpath: //button[@class='ml-2 mt-2 v-btn v-btn--depressed theme....']

If you do not need to use all value, you can use contains keyword:

  • xpath: //button[contains(@class, 'ml-2 m2-2')]
  • css: button[class*='ml-2 m2-2']

Of course, this value must be unique.

  1. You can search child element and return back to the parent:
  • //button/span[@class='v-btn__content']/i/../..
  1. You can use text for searching (bad practics if location possible to change)
  • //button/span[text()='Überspringen']/..
Related