【问题标题】:Unable to identify extjs date field with partial ID无法识别带有部分 ID 的 extjs 日期字段
【发布时间】:2018-07-31 04:55:41
【问题描述】:

我正在ExtJS 开发一个应用程序,它本质上是非常动态的。我正在使用 selenium Webdriver,我可以使用 Partial ID(包含、Startwith 等)在页面中找到文本字段、组合框,但无法在同一页面中找到日期字段(注意:只有一个日期字段存在于页面中。)。请帮我识别这个日期字段对象。

我可以使用以下代码访问组合框:

WebElement comb = driver.findElement(By.xpath(“//input[contains(@id, ‘combo’)]”));

尝试使用以下内容但无法找到日期字段:

WebElement dateBox = driver.findElement(By.xpath(“//input[contains(@id, ‘datefield’)]”));

HTML 详细信息:

<input id=”datefield-1217-inputEl” data-ref=”inputEl” type=”text” role=”textbox” size=”1″ name=”dateOfBirth” maxlength=”10″ class=”x-form-field x-form-required-field x-form-text x-form-text-default x-form-invalid-field x-form-invalid-field-default” autocomplete=”off” componentid=”datefield-1217″>

【问题讨论】:

    标签: java selenium-webdriver extjs datefield


    【解决方案1】:

    ExtJS 具有通过 ext id(可能与 HTML elementID 不同)检索元素的现有功能。但是一旦你知道了元素的 ext id,你就可以使用这个 ext 函数来检索元素 id:Ext.getCmp("your-Ext_id").getInputId(),然后你就可以通过这种方式使用它来获取 HTML 元素:

    document.getElementById(Ext.getCmp("your-Ext_id").getInputId());
    

    请看这个fiddle

    【讨论】:

      【解决方案2】:

      我有一个解决方案。在代码中添加了 Javascript

      JavascriptExecutor jsexc3 = (JavascriptExecutor) driver;
      
      jsexc3.executeScript("Ext.getCmp('Componentname').queryById('formname').down('#itemId').setValue('"10/10/1990"')");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-10
        • 1970-01-01
        • 2020-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多