-3

That is the HTML piece of the element which i need to click, I am getting "org.openqa.selenium.InvalidSelectorException"

<svg viewBox="0 12.705 512 486.59" xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns="http://www.w3.org/2000/svg" height="20" width="20" style="margin-right: 
0px;">

<svg viewBox="0 12.705 512 486.59" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns="http://www.w3.org/2000/svg" height="20" width="20" style="margin- 
right: 0px;">
<defs>
<polygon points="256.814,12.705 317.205,198.566 512.631,198.566 
354.529,313.435 414.918,499.295 256.814,384.427 98.713,499.295 
159.102,313.435 1,198.566 196.426,198.566 " style="fill: 
url(#jRate_grad4);stroke:black;fill-opacity:1;stroke-width:2px;">
</svg>

I used below code:

>WebElement ele = driver.findElement(By.xpath(".//*[@id='jRate']/svg[5]/"));
>JavascriptExecutor js = (JavascriptExecutor)driver;
>js.executeScript("argument[0].click()", ele);

I tried to find the element and just click on it, because of exception, I used JavaScript and issue is same. I don't know what I am missing here.

Java related help is much appreciated.

13
  • Remove the closing / from the xpath. Commented Oct 23, 2018 at 11:26
  • still not working! Commented Oct 23, 2018 at 11:29
  • Remove dot from xpath and last closing / - use this - //*[@id='jRate']/svg[5] Commented Oct 23, 2018 at 11:29
  • @Dhru'soni ok, that changed the exception "org.openqa.selenium.NoSuchElementException" is now on screen. Commented Oct 23, 2018 at 11:31
  • 1
    @SaiKrishnaPulivarthi Instead of being offensive and criticize "moderators" look at your question once more and ask yourself "Is my question good? Did I share enough information to receive good answer?". I think the answer will be "No". This ticket contain solution for handling svg-nodes. Also your solution (from comment) doesn't match your question Commented Oct 23, 2018 at 13:18

1 Answer 1

0

Your xpath is invalid. Remove the trailing slash

Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, I forgot to remove it when changing Xpath, actually even after removing it, the error is same. "org.openqa.selenium.NoSuchElementException"
That is a different error message. It indicates that it cannot find any element with that xpath. Without seeing the HTML it is hard to help further
<svg viewBox="0 12.705 512 486.59" xmlns:xlink="w3.org/1999/xlink" xmlns="w3.org/2000/svg" height="20" width="20" style="margin-right: 0px;"> <defs> <polygon points="256.814,12.705 317.205,198.566 512.631,198.566 354.529,313.435 414.918,499.295 256.814,384.427 98.713,499.295 159.102,313.435 1,198.566 196.426,198.566 " style="fill: url(#jRate_grad4);stroke:black;fill-opacity:1;stroke-width:2px;"> </svg>
Robbie, please check the above HTML code, it wont allow me to add to body of question, hence here.
That is the html of the element you are expecting to return, no? Can you provide the HTML that the search will be executed within?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.