selenium webdriver:org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互 [英] selenium webdriver: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
问题描述
我正在尝试使用文本克隆概念单击跨度.以下是html
I am trying to click on the span with the text- clone concept. Following is the html
<ul class="context-menu-list context-menu-root" style="width: 210px; top: 500px; left: 231px; z-index: 2;">
<li class="context-menu-item">
<li class="context-menu-item">
<li class="context-menu-item disabled">
<li class="context-menu-item">
<li class="context-menu-item icon icon-evn-icon-clone-concept">
<span>Clone concept</span>
</li>
<li class="context-menu-item">
<li class="context-menu-item icon icon-delete disabled">
</ul>
我使用的 javascript 代码是:
the javascript code i use is:
driver.findElement(By.xpath("//span[text()='Clone concept']")).click();
我通过 firepath 验证了这对元素来说是正确的.
I verified that this is the right for the element through firepath.
我还确保元素根据链接可见 如何强制 Selenium WebDriver 单击当前不可见的元素?
I also made sure that element is visible as per the link How to force Selenium WebDriver to click on element which is not currently visible?
这是计算的css
font-family Verdana,?Arial,?Helvetica,?sans-serif
.context-menu-list Verdana,?Arial,?Helvetica,?sans-serif
jquery...enu.css (line 15)
body Arial,?Helvetica,?sans-serif
swa.css (line 3)
font-size 11px
.context-menu-list 11px
jquery...enu.css (line 15)
list-style-type none
.context-menu-list none
jquery...enu.css (line 15)
还尝试了以下代码:
WebElement foo = driver.findElement(By.xpath("//span[text()='Clone concept']"));
Actions bar = new Actions(driver);
bar.click(foo).perform();
例外:org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互命令持续时间或超时:30.04 秒构建信息:版本:'2.24.1',修订版:'17205',时间:'2012-06-19 16:53:24'系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.7.0'驱动信息:driver.version:RemoteWebDriver
Exception: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 30.04 seconds Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 16:53:24' System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0' Driver info: driver.version: RemoteWebDriver
任何帮助将不胜感激.
对于那些卡在这里的人的另一个黑客:
目前,我已经能够通过将这个庞大的测试用例拆分为更简单的测试用例来继续前进.
Another hack for those who get stuck here:
For the time being I have been able to move forward by splitting this huge test case into simpler test cases.
推荐答案
不幸的是,Webdriver 似乎不太擅长处理您的问题中描述的情况.不过你有几个选择.使用 Javascript 模拟点击:
Unfortunately Webdriver doesn't seem to be great at handling situations like that described in your questions. You have a couple of options though. Mock a click using Javascript:
JavascriptLibrary jsLib = new JavascriptLibrary();
jsLib.callEmbeddedSelenium(selenium,"triggerMouseEventAt", elementToClick,"click", "0,0");
或
((JavascriptExecutor) driver).executeScript("arguments[0].click();", elementToClick);
或者您可以尝试使用操作来单击菜单链中的所有元素.不幸的是,我发现这不可靠.
Or you can play around with using actions to click all of the elements in the menu chain. Unfortunately I have found this to be unreliable.
我有一个脚本,它检测一个元素是否在菜单链中,如果它按要求的顺序点击它们,最终点击用户想要的那个,如果你想要的话,我可以把它张贴在某个地方,但它不是't 漂亮或短.
I have a script which detects whether an element is in a menu chain and if it is clicks on them in the required order to finally click on the one the user wanted if you want it I can post it somewhere but it isn't pretty or short.
这篇关于selenium webdriver:org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!