Selenium WebDriver: clicking on elements within an SVG using XPath

前端 未结 8 1215
难免孤独
难免孤独 2020-11-28 23:02

I have an SVG object with a few circle and rectangle elements. Using webdriver, I can click on the main svg object, but not any of the elements within it. The problem only s

相关标签:
8条回答
  • 2020-11-28 23:37

    Try this workaround :

    WebElement mapObject = driver.findElement(By.xpath("//*[name()='svg']/*[name()='rect']"));
    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", mapObject);
    

    Whenever I have too many problems with some elements while trying to click them, I use this workaround.

    0 讨论(0)
  • 2020-11-28 23:37
    actual = driver.findElement(By.xpath(
    "//div[contains(@class,'review-action')]//div[contains(@class,'rating')]/*[name()='svg'][1]/*[name()='g']/*[name()='path'][2]"))
    .getAttribute("stroke");
    
    0 讨论(0)
提交回复
热议问题