如何在ExtJS页面上找到与Selenium一起使用的元素的唯一选择器? [英] How to find unique selectors for elements on pages with ExtJS for use with Selenium?

查看:151
本文介绍了如何在ExtJS页面上找到与Selenium一起使用的元素的唯一选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Firefox Webdriver的Selenium来处理具有唯一
CSS ID(每个页面加载)的页面上的元素,但每次都会更改ID,因此我无法使用它们来定位元素。这是因为该页面是使用ExtJS构建的Web应用程序。



我正在尝试使用Firebug来获取元素信息。



我需要找到一个唯一的xPath或选择器,所以我可以用Selenium单独选择每个元素。



我使用Firebug来复制xPath我得到一个这样的值:

  // * [@ id =ext-gen1302] 

但是,下次加载页面时,看起来像这样:

  // * [@ id =ext-gen1595] 

在该页面上,每个元素都具有此ID格式,因此不能使用CSS ID来查找元素。



我想获得与DOM中的位置相对应的xPath,但是Firebug将只返回ID xPath,因为该页面对于该页面的实例是唯一的。

  / html / body / div [4] / div [3] / div [4 ] / div / div / div / span [2] / span 

如何获取Firebug另一个可以以类似速度工作的工具)给我一个唯一的选择器,可以用来找到带有Selenium的元素,即使在ext-id ID变化之后?

解决方案

ExtJS UI自动化测试的另一个受害者,这里是我的专门用于测试ExtJS的提示。 (但是,这不会回答您的标题中描述的问题)



提示1:不要使用不可读XPath,如code> /格[4] / DIV [3] / DIV [4] / DIV / DIV / DIV /跨度[2] /跨度。源代码的一个微小变化可能导致DOM结构的变化。这将导致巨大的维护成本。



提示2:利用有意义的自动生成的部分ids和类名。



例如, ExtJS网格示例: By.cssSelector(。x-grid-view .x-grid-table) 会很方便。如果有多个网格,请尝试对它们进行索引或找到可识别的祖先,例如 By.cssSelector(#something-useful .x-grid-view .x-grid-table)



提示3:在源代码中创建有意义的类名。 ExtJS为自定义类名提供 cls tdCls ,因此您可以添加 cls:'testing -btn-cancel'在您的源代码中,并通过 By.cssSelector(。testing-btn-cancel) p>

Tip3 是最好的,最后一个。如果您无法访问源代码,请与您的经理沟通,Selenium UI自动化应该是一名可以修改源代码而不是最终用户的测试人员的开发者工作。


I am using Selenium with Firefox Webdriver to work with elements on a page that has unique CSS IDs (on every page load) but the IDs change every time so I am unable to use them to locate an element. This is because the page is a web application built with ExtJS.

I am trying to use Firebug to get the element information.

I need to find a unique xPath or selector so I can select each element individually with Selenium.

When I use Firebug to copy the xPath I get a value like this:

//*[@id="ext-gen1302"]

However, the next time the page is loaded it looks like this:

//*[@id="ext-gen1595"]

On that page every element has this ID format, so the CSS ID can not be used to find the element.

I want to get the xPath that is in terms of its position in the DOM, but Firebug will only return the ID xPath since it is unique for that instance of the page.

/html/body/div[4]/div[3]/div[4]/div/div/div/span[2]/span

How can I get Firebug (or another tool that would work with similar speed) to give me a unique selector that can be used to find the element with Selenium even after the ext-gen ID changes?

解决方案

Another victim of ExtJS UI automation testing, here are my tips specifically for testing ExtJS. (However, this won't answer the question described in your title)

Tip 1: Don't ever use unreadable XPath like /div[4]/div[3]/div[4]/div/div/div/span[2]/span. One tiny change of source code may lead to DOM structure change. This will cause huge maintenance costs.

Tip 2: Take advantage of meaningful auto-generated partial ids and class names.

For example, this ExtJS grid example: By.cssSelector(".x-grid-view .x-grid-table") would be handy. If there are multiple of grids, try index them or locate the identifiable ancestor, like By.cssSelector("#something-meaningful .x-grid-view .x-grid-table").

Tip 3: Create meaningful class names in the source code. ExtJS provides cls and tdCls for custom class names, so you can add cls:'testing-btn-cancel' in your source code, and get it by By.cssSelector(".testing-btn-cancel").

Tip3 is the best and the final one. If you don't have access the source code, talk to your manager, Selenium UI automation should really be a developer job for someone who can modify the source code, rather than a end-user-like tester.

这篇关于如何在ExtJS页面上找到与Selenium一起使用的元素的唯一选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆