2

I have a problem with clicking on svg element in selenium Java.

HTML code: enter image description here

I have tried next code examples but they are not helped.

Actions action = new Actions(webDriver);
action.click(webElement).build().perform();
JavascriptExecutor executor = (JavascriptExecutor) webDriver;
executor.executeScript("arguments[0].click;", webElement);
Actions action = new Actions(webDriver);
Thread.sleep(2000);
action.moveToElement(webElement).click().build().perform();

I did not get any exception or error. But can not click on SVG element Which solutions are exist for it?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
tester
  • 95
  • 1
  • 7

1 Answers1

0

The desired element is a element so to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

compatible code

  • Using cssSelector:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[placement='bottom'] svg"))).click();
    
  • Using xpath:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@placement='bottom']//*[name()='svg']"))).click();
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352