【问题标题】:ExtJS+Selenium: @value gives nothingExtJS+Selenium:@value 什么也没给
【发布时间】:2012-06-07 03:39:41
【问题描述】:

我正在使用只读表单并将其加载到控制器中

"popup.down('form').loadRecord(record);"

表单字段定义为

items:[
{
  xtype:'textfield',
  fieldLabel:'Array Id',
  name:'id'
},
{
  xtype:'textfield',
  fieldLabel:'Array Name',
  name:'name'
}
]

值:[ id:10, name: 'testing']

生成的HTML代码是:

<form id = 'arraydevicewindowid'>

  <input type="text" autocomplete="off" class="x-form-field x-form-text" size="20"     name="${array.arrayName}" id="ext-gen1314" readonly="" aria-readonly="true" aria-invalid="false" placeholder="--NA--" role="textbox" aria-describedby="textfield-1260-errorEl" aria-required="false" data-errorqtip="" style="width: 281px; height: 23px;">

</form>

我尝试使用以下 xpath 从 Extjs 生成的文本字段组件中选择值:

(//div[@id='arraydevicewindowid']//input)[1]//@value

但没有运气。

(//div[@id='arraydevicewindowid']//input)[1]

可以让我选择我想要的文本字段,但@value 不起作用。

有什么想法吗?

【问题讨论】:

  • 您使用的是哪种 Selenium? Selenium IDE(Firefox 插件)、Selenium RC(旧的和已弃用的,但仍然可用)或 Selenium WebDriver(到处使用 WebDriver 的新的、闪亮的)?

标签: extjs selenium


【解决方案1】:

问题是 Selenium 不能使用 XPaths 返回除 HTML 元素之外的任何内容。但是value 属性...是节点的属性,XPath 本质上返回一个字符串。因此,您必须选择正确的元素,然后使用 Selenium 内置方法获取其值。

使用 Selenium IDE:storeValue 的某种魔法。

使用 Java + Selenium RC:

// assuming 'selenium' is a healthy instance of Selenium
String value = selenium.getValue("xpath=yourXpath");

使用 Java + Selenium WebDriver:

// assuming 'driver' is a healthy instance of WebDriver
String value = driver.findElement(By.xpath('yourXpath')).getAttribute("value");

【讨论】:

    猜你喜欢
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多