如何使用Selenium检查<canvas>元素的兄弟元素?

时间:2016-10-26 13:03:26

标签: java selenium firefox firebug

以下是HTML结构的一部分,其中包含<canvas>元素,其中两个<div>元素为兄弟姐妹:

<div id="block_container" style="width: 255px; cursor: pointer;">
    <canvas tabindex="0" style="position: absolute; top: 0px; left: 0px; z-index: 2; -moz-user-select: none; width: 255px; height: 912px; cursor: pointer;" width="318" height="1140" title="Address.csv">Your browser is not capable to show this part of HTML</canvas>
    <div style="position: absolute; overflow: auto; width: 255px; height: 912px; z-index: 1;">
        <div style="position: absolute; width: 1px; height: 1px;"/>
    </div>
    <div style="position: absolute; overflow: auto; width: 255px; height: 912px; z-index: 1;">
        <div style="position: absolute; width: 1px; height: 1px;"/>
    </div>
</div>

现在在这个<canvas>元素中,我无法在Firefox上使用Firebug检查任何元素。每当我在检查时悬停元素时,只会突出显示<canvas>元素。

有谁能说出如何克服这个问题?因为只要我无法检查任何元素,我就无法继续Selenium中的自动化。

另外,让我知道一旦可以识别元素,如何使用Selenium处理此问题。

1 个答案:

答案 0 :(得分:1)

查看您的z-index属性。

canvas的z-index为2,而div的z-index为1。

现在看一下z-index的定义:

  

堆栈顺序较大的元素始终位于堆栈顺序较低的元素前面。

看来你的问题是canvas元素总是位于你的div之上。