【问题标题】:Salesforce custom objects accessing using selenium webdriver with javaSalesforce 自定义对象使用 selenium webdriver 和 java 访问
【发布时间】:2018-04-26 00:17:27
【问题描述】:

每次 SalesForce 发布新版本时,salesforce 网页上的大部分元素 ID 都会发生变化(我使用元素的 ID 属性通过我的自动化代码来定位它)。这会破坏我的自动化脚本。

在我的例子中,一个名为“问题名称”的文本框我想在这个文本框中输入一个值。

最近的html:

<label class="label inputLabel uiLabel-left form-element__label uiLabel" for="7:1781;a" data-aura-rendered-by="1040:0" data-aura-class="uiLabel">
<span class="" data-aura-rendered-by="1041:0">Question Name</span>
<span class="required " data-aura-rendered-by="8:1781;a">*</span>
</label>
<input id="7:1781;a" class=" input" maxlength="80" aria-describedby="" placeholder="" required="" data-aura-rendered-by="11:1781;a" 
data-interactive-lib-uid="5" aria-required="true" type="text">

我现有的 xpath:

driver.findElement(By.xpath("//input[@id='6:2634;a']")).sendKeys("test");

Salesforce 应用程序的所有 ID 都会针对每个新版本动态更改,我的测试脚本因上述带有 ID 的 xpath 而失败,所以请建议我替代解决方案。

我应该如何在运行时获取输入 id 值?或者让我知道是否还有其他可能。

【问题讨论】:

    标签: java selenium xpath selenium-webdriver salesforce


    【解决方案1】:

    您可以使用以下内容:

    driver.findElement(By.xpath("//label[contains(., 'Question Name')]/following-sibling::input")).sendKeys("test");
    

    这将搜索包含文本“问题名称”的标签,然后选择以下输入兄弟

    【讨论】:

      【解决方案2】:

      要在名为 "Question Name" 的文本框中输入值,您可以使用以下代码行:

      driver.findElement(By.xpath("//label[@class='label inputLabel uiLabel-left form-element__label uiLabel']/span[text()='Question Name']//following::input")).sendKeys("test");
      

      【讨论】:

      • 感谢您的帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多