Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes How to get xpath of an element on click. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to get xpath of an element on click." Watch "How to get xpath of an element on click." New topic
Author

How to get xpath of an element on click.

Freiza Gen
Greenhorn

Joined: Nov 07, 2013
Posts: 19
How to get xpath of an element on click in java.


Suppose I click on a textbox (html) and I want to retrieve its id, name and value. What should I do?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Freiza Gen wrote: ...
Suppose I click on a textbox (html) and I want to retrieve its id, name and value. What should I do?


This is HTML, so you could use DOM events to do these stuff as they are client side operations. I don't think you need Java to do this. You could of course pass these data to Java backend to do any processing once retrieved.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Freiza Gen
Greenhorn

Joined: Nov 07, 2013
Posts: 19
I am still not getting it.

I have not created the website.

Let us assume I want to get the xpath of textbox of any page (say yahoo.com). Do I have to inject javascript?
I want function similar to firepath.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 464
    
    2
The xpath to an element is by no mean unique - it depends on how you look at it. This firefox add-on may help you hook at least to something to start with.
https://addons.mozilla.org/en-US/firefox/addon/xpath-checker/
Freiza Gen
Greenhorn

Joined: Nov 07, 2013
Posts: 19
In firefox we can right click textbox or button or any other html element and select "inspect element" it shows the html code for it. I just want to get the DOM path/xpath in similar way.

Is there any way to do it. And I don't want to use any tools or addons. I want to write the code myself.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

I imagine that there are tutorials somewhere on the web on how to write browser add-ons. It's not the sort of thing that someone is going to teach you how to do in a forum post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get xpath of an element on click.
 
Similar Threads
How do I use DOM to gather information on an XML file with repeating child elements?
What is in your Java/J2EE ToolBox?
Find XPath
problem with my xpath in selenium. getting a invalid xpath error
XPATH Question