Python Forum

Full Version: Find element using xpath
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to code an Instagram Bot using python and selenium.
I want to find an element using xpath
The Html path is as below:

<div class="_2ic5v">
<button class="wpO6b ZQScA" type="button">
<svg aria-label="Like" class="_8-yf5 " fill="#8e8e8e" height="12" viewBox="0 0 48 48" width="12"><path d="......."></path>

My best guess so far is find_elements_by_xpath('//button[@class="ZQScA"]/*[name()="svg"][@aria-label="Like"]')[0]
the easiest way to get an xpath is to use the inspect function of your browser.
for Firefox the procedure is:
  • move cursor over desired element
  • right click and select inspect Element(s)
  • In the inspection window, hover over the highlighted html
  • right click and select Copy --> Xpath
  • Paste into your code

Chrome is similar
I've tried that but I don't get anything from that code. I've used both copy xpath and copy full xpath.

I was hoping to get an understanding of how a xpath code is composed.
OK, here's something to start with: https://www.softwaretestinghelp.com/xpat...-examples/