Selenium WebDriver: clicking on elements within an SVG using XPath

前端 未结 8 1299
难免孤独
难免孤独 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:28

    I have different high charts in my project and my aim was to double click on a section of a chart to drill down for further information and I've managed to do it using following lines of code. XPath didn't work for me but CssSelector worked just fine.

    var elementToClick= Browser.Driver.FindElementEx(By.CssSelector("#highcharts-0 > svg > g.highcharts-series-group > g.highcharts-series.highcharts-tracker > path:nth-child(1)"), 10);
    Actions action = new Actions(Browser.Driver);
    action.Click(elementToClick).Build().Perform();
    action.DoubleClick(elementToClick).Build().Perform();
    

提交回复
热议问题