Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find element using xpath
#1
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]
Reply
#2
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
Reply
#3
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.
Reply
#4
OK, here's something to start with: https://www.softwaretestinghelp.com/xpat...-examples/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find element in a deeply nested html structure Orientation_group 5 1,283 Oct-09-2023, 10:13 AM
Last Post: Larz60+
  how can I find this by tag, instead of XPATH? hfakoor2 3 1,215 Mar-13-2023, 04:27 AM
Last Post: hfakoor2
  Selenium suddenly fails to find element Pavel_47 3 6,304 Sep-04-2022, 11:06 AM
Last Post: Pavel_47
  find element...click() dont work windows11 6 3,136 Apr-23-2020, 11:13 PM
Last Post: law
  Find Dynamic Input Element Class Problem wazacko 0 1,601 Apr-03-2020, 11:46 AM
Last Post: wazacko
  bypassing find element click() windows11 1 1,881 Apr-02-2020, 11:55 AM
Last Post: Larz60+
  How find link element zinho 3 3,119 Mar-31-2020, 12:29 PM
Last Post: snippsat
  need help with xpath pythonprogrammer 1 2,762 Jan-18-2020, 11:28 PM
Last Post: snippsat
  How to find which frame/iframe my element belongs to? smaria 1 2,058 Nov-18-2019, 09:21 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020