0

I want to know is it possible to get xpath of the element such that link="Edit".

Using selenium can i achieve this.

Explanation :

I know that on page there is link with with text "Edit". So using selenium i can locate it dynamically such that link="Edit" but now i have this link in my RC and want to loop it using its xpath so that i can get contents in the same row where link is present.

I want to achieve these kind of things in different scenarios and with different elements. I should be able to get the xpath, id, css of elements using attributes of elements.

Please help, let me know is it possible using some java-script or else I am using Selenium RC with PHP. If possible i should be able to integrate things.

Thanks in advance.

lAH2iV
  • 1,159
  • 2
  • 12
  • 28
  • after you record an action in Selenium IDE, it lets you choose the type of selector you want to use for each target.. i don't know about Selenium RC, but it has been officially deprecated - try to switch to Selenium WebDriver, if possible :)) – Aprillion Apr 23 '12 at 06:34
  • Thanks for reply but my dynamically check whether the element is present on any of the entry in the table and if the link is present i have to take the name of the entry. So is there any way to get the xpath on the go. – lAH2iV Apr 23 '12 at 06:59
  • 1
    I believe what you really want is to spend some time studying [XPath](http://en.wikipedia.org/wiki/XPath) and/or [CSS selectors](http://en.wikipedia.org/wiki/CSS_selector#Syntax) and what they can do. Try googling, of course, the most deep (but still very readable) read are the specs: [XPath 1.0](http://www.w3.org/TR/xpath/) and [CSS 2 selectors](http://www.w3.org/TR/CSS2/selector.html). – Petr Janeček Apr 23 '12 at 10:33

1 Answers1

1

i don't know about "on the go" creating of xpath, but this is an xpath equivalent for link="Edit" in Selenium:

//a[contains(text(), 'Edit')]/..
Aprillion
  • 21,510
  • 5
  • 55
  • 89
  • Thanks but this will not help me as this will get me only the link locator i will be not able to get the value present in the same row with this. – lAH2iV Apr 23 '12 at 07:43
  • 1
    @lAH2iV if by "same row" you mean its parent, see updated answer with relative path `/` followed by a parent expression `..` – Aprillion Apr 23 '12 at 07:50
  • :Tanks for ur help using this `//a[contains(text(), 'Edit')]/../../td[3]` i was able to get the name where edit button was present. Thanks again. So using contains i can get labels and buttons too? – lAH2iV Apr 23 '12 at 10:08
  • can i get such things from isTextPresent() in selenium and get the xpath of the text where it found please let me know, Thanks in Advance – lAH2iV Apr 23 '12 at 10:11
  • 1
    i'm not sure what are you asking - **text()** searches for text between opening and closing tag,, **@value** will search for value attribute of an `` element if your buttons are input[type=button]... – Aprillion Apr 23 '12 at 10:32
  • can u give me link to these kinds of locators which will help me to study on them. I want my code should dynamically search all elements as per testcases contents. So i will need this. – lAH2iV Apr 23 '12 at 12:06
  • 1
    see selenium documentation first: http://seleniumhq.org/docs/02_selenium_ide.html#locating-elements, there are usefull links in that sections for XPATH too (i just google other stuff beside basics) – Aprillion Apr 23 '12 at 15:13