Below are the simple steps to find XPath of a button on a web page in Google Chrome.
Let’s try to find the XPath of ‘Subscribe’ button on Gethowstuff.com’s homepage.
Steps to find XPath of button
- Open Gethowstuff.com in Google Chrome
- Right-Click on Subscribe button and click on Inspect
3. Right-Click on the highlighted area on the console
4. Go to Copy -> Click on Copy XPath
That’s it. The XPath of the button is copied. Follow same steps to find XPath of any button on the webpage.
When you paste XPath in Python code, replace double quotes of the id with single quotes. Otherwise, you may get syntax error
Example: //*[@id=”text-2″]/div/form/input to //*[@id=’text-2′]/div/form/input
To know how to use it in a script visit Python selenium script – click a button on web page using xpath