Selenium C#:在图表上找到元素

时间:2015-06-01 23:19:20

标签: javascript c# selenium xpath selenium-webdriver

我想识别此图表上的stimulusFrequency圈子,以便点击并拖动它们。enter image description here

<svg class="svg-graph-content graphEventHandler ng-valid" ng-model="hearingGraph" viewBox="0 0 470 355" preserveAspectRatio="none">
<path class="" ng-show="audiogram.leftEnabled" ep-d="M42 148.39999389648438 L126 148.71843558091385 L210 147.23333740234375 L294 147.86266635014462 L378 147.86266635014462 L462 147.86266635014462" fill-opacity="0" stroke-width="2" stroke="rgb(0,0,255)" d="M42 148.39999389648438 L126 148.71843558091385 L210 147.23333740234375 L294 147.86266635014462 L378 147.86266635014462 L462 147.86266635014462" style="">
<circle class="" ng-touch="manualGraph($event, c, 'left')" ng-mousedown="manualGraph($event, c, 'left')" ng-show="audiogram.leftEnabled && manual" ng-repeat="c in audiogram.tonePoints | filter: {'resultSet': 'left'} | orderBy : 'stimulusFrequency'" fill="black" ep-r="8" ep-cy="148.39999389648438" ep-cx="42" cy="148.39999389648438" cx="42" r="8">

我要与之交互的图表部分是“圈子类”,使用firebug,我发现其中一个圈子的XPath如下所示,但我得到了“没有这样的元素”例外。

.//*[@id='layout-wrapper']/ui-view/ui-view/div/ep-annotation-widget/div/div/div/div[1]/div[4]/div[1]/div[2]/svg/circle[1]

我使用以下方面取得了一些进展:

var circles = Driver.Instance.FindElements(By.TagName("circle")); 

但是当只有12个结果时,这会产生27个结果,所以我会继续努力。

1 个答案:

答案 0 :(得分:0)

这就是我想出的。如果你有更有效的方法,请告诉我。

    public static void MoveNode(string ear, int frequency)
    {
        int circleRef = 0;
        switch (frequency)
        {
            case 250:
                if (ear == "right")
                {
                    circleRef = 12;
                }
                else if (ear == "left")
                {
                    circleRef = 0;
                }
                break;
            case 500:
                if (ear == "right")
                {
                    circleRef = 13;
                }
                else if (ear == "left")
                {
                    circleRef = 1;
                }
                break;
        }
        var circles = Driver.Instance.FindElements(By.TagName("circle"));
        circles[circleRef].Click();
        //add logic for dragging and releasing
    }