Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

XPath expression to select all button or input type submit/button elements

I’m writing a Python script that uses Selenium to select all clickable buttons by XPath.

I have these XPath expressions:

//button
//input[@type='submit']
//input[@type='button']

Is there a way to join these in a single XPath expression, to select only these types of elements?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can check for the names and the attributes

//*[name()='button' or (name()='input' and (@type='submit' or @type='button'))]

or use the merge operator on three different queries

//button | //input[@type='submit'] | // input[@type='button']

Output should be the same, but the resulting order may be different.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading