1

Following is the element that I located using xpath:

element2 = element1.find_element(:xpath, ".//a")

xpath is .//a

I want to convert it to css. What is equivalent css of it?

Note: . is important in .//a because I want to find it with respect to element1

Similarly, what could be css equivalent of ..//a

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • you do not really require the first element reference to find the second element using xpath. Also a . is not really necessary in xpaths, creates more problems than it helps. If you can share the html I can help you out. – Vinay Nov 19 '13 at 10:37
  • The things, I mentioned in my questions are simple one and that is only for better understanding of what I want to achieve. Basically, I'm looking for migrating xpaths from my scripts to css. – Alpha Nov 19 '13 at 11:38

1 Answers1

0

css equivalent for .//a is a with white-space before it (e.g. div a will find all a in all divs). This will find all elements with tag name a on any level inside parent element. For more information you can visit this

So your code will be the following: element2 = element1.find_element(:css, " a") I don't sure about :css because i don't know the language you are using.

ievche
  • 1,735
  • 14
  • 22
  • Thanks Evgenity! Could you please me css for `..//a`? I mean what is for `..` – Alpha Nov 20 '13 at 05:47
  • Unfortunately there are no equivalent for `../` in css. Check [this](http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector) – ievche Nov 20 '13 at 09:13
  • Ok, thanks Evgenity. Accepted your answer since it helped to achieve `.` :) – Alpha Nov 20 '13 at 09:40