Sencha禁用按钮和Selenium Web驱动程序
Sencha Disabled Button and Selenium Webdriver
我在一个用sencha/extjs构建的网站上有一个按钮。当前按钮id为savebutton-1550-btnEl,但每次加载页面时都会更改。我知道这个按钮是禁用的,但出于测试目的,我想把这个按钮设置为启用,然后点击它
我应该如何每次都找到这个元素,然后禁用它并用JavaSelenium单击它?
我想我将不得不执行一些javascript,但我很难找到javascript的目标。
要定位元素,必须使用元素周围DOM的一部分作为唯一定位器。如果没有看到您正在处理的DOM,就不可能给出更具体的答案,但您可以尝试以下方法:
WebElement saveButton = driver.findElement(By.xpath("//button[text()='Save']");
要将元素更改为enabled
,请查看以下答案:Selenium Webdriver-单击隐藏元素
此外,一个长期的解决方案可能是与开发人员合作,看看他们是否可以构建一个唯一的定位器,尤其是因为这可能不是您遇到问题的唯一对象。在我的公司,我们使用"class"字段来唯一标识extjs中的对象。
我覆盖类"AbstractComponent":
Ext.define('Foo.overrides.AbstractComponent', {
override: 'Ext.AbstractComponent',
onBoxReady: function () {
var me = this;
var el = me.getEl();
if (el && el.dom && me.itemId) {
el.dom.setAttribute('data-test', me.itemId);
}
me.callOverridden(arguments);
}
});
如果你在按钮的配置中设置了"itemId",你可以通过seleniuma访问按钮如下:
IWebElement element = webDriver.FindElement(By.XPath($"//*[@data-test='{itemId}']"));
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- WebDriverException:tinyMCE未在selenium Web driver java中定义
- Selenium Web驱动程序和javascript
- Xpath对Selenium Web驱动程序无效”;Xpath未找到”;
- Sencha禁用按钮和Selenium Web驱动程序
- 如何使用Selenium Web驱动程序验证电子邮件
- 在Selenium Web驱动程序2.0中找不到元素
- 使用Java脚本跟踪网页中是否有Ajax请求,或者通过Selenium Web驱动程序拦截XMLHttpRequest
- 元素找不到带有文本的selenium Web驱动程序
- 无法使用Javascript和Selenium Web驱动程序保存保存在表单元格中的文本
- Selenium Web驱动程序访问Jquery中的Javascript全局变量
- Selenium Web驱动程序使用Java查找Element
- C#Selenium Web驱动程序在Internet explorer中捕获javascript错误
- 获取 selenium Web 驱动程序 java 中元素的类名
- 使用Selenium Web驱动程序注入自定义JS代码
- 用于解析的Selenium Web驱动程序(Ruby)
- Selenium Web驱动程序的执行由于javascript等待条件而陷入停滞
- 如何使用selenium web驱动程序单击导航栏
- Selenium Web驱动程序定位器
- Selenium Web驱动程序:execute_script can't执行自定义方法和外部javascrip