Selenium can't find element by xpath

后端 未结 4 2231
半阙折子戏
半阙折子戏 2021-01-06 15:14

I\'ve been working at this for some time now. I\'m using Selenium and WebDriver version 2.33 (with all browsers). I\'m using Java, which should be arbitrary. What I\'m doing

相关标签:
4条回答
  • 2021-01-06 15:45

    Try as CSS Selectors :

    By by = By.css('div[id^="highcharts"] g[class^="highcharts"] > g > rec')
    

    g.class_name I used,as that <g> tags class name is not visible. Replace that class name with the proper class name.

    0 讨论(0)
  • 2021-01-06 15:52

    I just wanted to give a slight update on this. It seems selenium can't see past the SVG tags, so with that being said, I need to find a method to see around them...I will report back if I'm able to find out how.

    Thanks all!

    0 讨论(0)
  • 2021-01-06 15:56

    From your discussion with Amey i deduced that you have only one highchart. so try directly searching for element "highcharts-tracker" using classname i.e By.ClassName("highcharts-tracker") and then hover on this element itself. This would exactly do what you want to achieve.

    0 讨论(0)
  • 2021-01-06 15:56

    Sorry just seeing your comment on my earlier answer. You can get the values for each bar in barchart by following way:

    var barValues = new List<string>(); 
    var actions = new Actions(webDriver); //webDriver is instance of selenium WebDriver.
    var chartSeriesGroup = webDriver.FindElement(By.ClassName("highcharts-series-group"));
    var chartSeries = chartSeriesGroup.FindElement(By.ClassName("highcharts-series"));
    var rectTags = chartSeries.FindElements(By.TagName("rect")); //To get all bars in barchart.
    
    foreach (var rect in rectTags)
    {
       actions.MoveToElement(rect).Perform(); //Hover mouse on bar.
       var trendMarkers = webDriver.FindElement(By.ClassName("highcharts-tooltip"));
       barValues.Add(trendMarkers.Text); //Storing tooltip value of bar for later use.
    }
    

    I am using same method in my current project for getting values of bars in bar chart. Hope this will help you.

    Note : If tooltip for bar shows other information e.g.name etc along with value then you need to write logic for extracting the value part from the complete information stored in barValues.

    0 讨论(0)
提交回复
热议问题