【问题标题】:Selenium C#: Locate element on chartSelenium C#:在图表上定位元素
【发布时间】:2015-08-15 14:02:01
【问题描述】:

我想识别这张图表上的刺激频率圆圈,以便我可以点击并拖动它们。

<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 个结果,所以我会继续努力。

【问题讨论】:

  • 你不能通过它的属性值的一个(或组合)来识别特定的圆供选择吗?这可以很容易地翻译成 xpath 表达式,f.e //circle[@cx=42 and @r=8]

标签: javascript c# selenium xpath selenium-webdriver


【解决方案1】:

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

    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
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 2019-01-08
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多