Python Forum
can i get any xpath on click event?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can i get any xpath on click event?
#1
i am trying to create an application where if i click any webpage text i can get xpath of the element?
suppose i click on image and can i get xpath of that image using python?
Reply
#2
if you are using firefox or chrome, there's an option to 'inspect element'.
On firefox, right click on page and select inspect element.
Navigate through the code until item of interest is highlighted.
left click on code line, then right click and click on copy choose Xpath and paste to your script.
Chrome is similar.
Reply
#3
No not like that...

for examples
import requests
from flask import Flask
app = Flask(__name__)

@app.route('/')
def get_data():
    data = requests.get('https://maharerait.mahaonline.gov.in/').text
    print(data)
    return data

app.run(debug=True)
this is my code which opens third party website.

if you run this you will get to see the text and page. i click on anytext on page to get the xpath?
i click and system prints the xpath without using 'inspect element' option


or forget xpath. if i can get tag associated with that text if i click on anytext written?
Reply
#4
Ok, I understand what you're looking for now.
Perhaps this will be of use: https://qxf2.com/blog/auto-generate-xpat...ng-python/
The clicking part will have to be written.
You'll have to write the clickable part, one way to do this, might be to load the HTML or XML into a GUI text widget, click on a line, and then use above tool to generate Xpath.

The other thing you might be able to do, is locate mozilla page inspector source in DevTools. I looked quickly, but couldn't find it.
Reply


Forum Jump:

User Panel Messages

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