Selenium IDE找不到Ext JS的列标题菜单

时间:2019-04-24 17:28:34

标签: javascript selenium extjs

我一直在使用Ext JS作为我的前端,并且我的网格的标题栏上都有带有菜单的列(只是标准的impl)。

标题上的菜单用于根据存储在其中的值启用或禁用商店中的过滤器。

我刚刚开始使用selenium来自动化一些前端测试,并且我发现Selenium不能在列标题菜单上找到click操作...

我在互联网上读到,我们需要为组件指定唯一的ID,以便Ext JS不会为其提供动态生成的ID。我为gridcolumn xtype设置了一个ID,但是我发现这不适用于标题菜单(或触发其打开的按钮)。

有人可以帮我将唯一的ID应用于显示菜单窗口的按钮,还是可以通过某种方式使Selenium找到标题菜单?

Ext JS column header menu

2 个答案:

答案 0 :(得分:1)

感谢@JimGrigoryan的建议!在桌面模式下切换到Kantu的硒后,使用XClick,XMove和XMoveRelative,我可以通过截屏来查找页面上的元素。现在,Ext Js赋予元素的动态ID无关紧要。

答案 1 :(得分:0)

尝试这样的事情

注意:您需要根据需要在代码栏中稍加调整。

//find header
WebElement header = findElement(By.xpath("//div[starts-with(.,'Specification Status')]"));

//Make mouse event hover on header for show the arrow
Actions action = new Actions(driver);
action.moveToElement(header).perform();

//click on arrow
header.findElement(By.cssSelector(".x-column-header-trigger")).click();

//Mouse over event on filter item, this element not linked on header
// findelement no DOM.
WebElement filtros = findElement(By.cssSelector("a[aria-label='Filters'"));
action.moveToElement(filtros).perform();

//find inputs, this element not linked to header
List<WebElement> searchFields = findElements(By.cssSelector("input[placeholder='Enter Filter Text...']"));

WebElement searchId = searchFields.get(0); //<<< here is according how many inputs is showed in your filters
action.moveToElement(searchId).perform();
searchId.sendKeys("Value to search");

Thread.sleep(1500);