使用selenium,java和Extjs框架选择元素

时间:2015-11-11 17:04:31

标签: javascript java selenium extjs extjs4

我试图点击Extjs框架生成的按钮。 我有这个HTML:

<a class="x-btn x-unselectable x-box-item x-toolbar-item x-btn-default-toolbar-small" hidefocus="on" unselectable="on" id="button-1022" tabindex="0" componentid="button-1022" style="right: auto; top: 0px; margin: 0px; left: 0px;">

<span id="button-1022-btnWrap" data-ref="btnWrap" role="presentation" unselectable="on" style="" class="x-btn-wrap x-btn-wrap-default-toolbar-small ">

  <span id="button-1022-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="" class="x-btn-button x-btn-button-default-toolbar-small x-btn-text    x-btn-button-center ">

   <span id="button-1022-btnIconEl" data-ref="btnIconEl" role="presentation" unselectable="on" class="x-btn-icon-el x-btn-icon-el-default-toolbar-small  " style=""></span><span id="button-1022-btnInnerEl" data-ref="btnInnerEl" unselectable="on" class="x-btn-inner x-btn-inner-default-toolbar-small">Nuovo</span>

</span>
</span>
</a>

此代码由Extjs框架生成。我想选择&#34; Nuovo&#34;文本,然后单击。我正在使用Selenium(2.42.2)和Java:

e = driver.findElement(By.id("button-1022")); 
e.click();

好的,它有效,但太具体了,我不想强​​迫身份。

所以我在努力:

WebElement e = driver.findElement(By.xpath("//*[contains(text(), 'Nuovo')]/../../.."));
WebElement e = driver.findElement(By.xpath("//*[contains(text(), 'Nuovo')]"));

使用这两种解决方案我都有这个错误:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

为什么使用By.id(..)它可行并使用xpath我有错误?

0 个答案:

没有答案