0

I am using Java and Selenium to write a test. In my DOM, I have two svg tags. One of them has more that 2 inner path tags. I need to get this svg so I used:

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(
                        "//*[local-name() = 'svg' and count(.//path)>'2']")));

or

 wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(
                            "//*[local-name() = 'svg'] [count(.//path)>'2']")));

but it doesn't work. I need to know what's wrong with that so please do offer other ways around. Thanks.

by the way it worked for:

//*[local-name() = 'svg' and count(.//*[local-name() = 'path' ])>'1']

or

//*[local-name() = 'svg'][ count(.//*[local-name() = 'path' ])>'1']
LoveLovelyJava one
  • 343
  • 1
  • 3
  • 16
  • 1
    Post relevant portion of your HTML. No one can tell why one xpath works but not the other without knowing the corresponding HTML/XML – har07 Apr 19 '16 at 23:35
  • Just a friendly tip, you may want to read over this page: [The How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your show code and any error messages! – Matt C Apr 20 '16 at 00:47

1 Answers1

0

The problem is you are trying to find .//path which is SVG element. As far as I know, you cannot do this because SVG elements are from different namespace. As you mentioned in your question, you can fix it by using [local-name() = 'path' ]. A workaround is using JSExecutor to execute method document.evaluate() so you can specify namespace of SVG. See example at this post.

Community
  • 1
  • 1
Buaban
  • 5,029
  • 1
  • 17
  • 33