【问题标题】:Unable to Locate an element for Salesforce Lightning无法找到 Salesforce Lightning 的元素
【发布时间】:2019-06-21 04:28:41
【问题描述】:

技术:

  • 销售人员
  • 闪电
  • Selenium 网络驱动程序

HTML:

<a href="/lightning/o/Acq_Prospect__c/home" title="Acq Prospects" tabindex="0" draggable="false" aria-describedby="operationId-20" class="slds-context-bar__label-action dndItem" style="" xpath="1"></a>

代码试用:

driver.findElement(By.xpath("//a[@title='Acq Prospects']"));
driver.findElement(By.linkText("Acq Prospect"));

错误:

Unable to find an element

【问题讨论】:

标签: selenium selenium-webdriver xpath css-selectors webdriver


【解决方案1】:

您只需要等待对象可见。您可以使用以下代码;

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.Until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='Acq Prospects']")));

更多信息; link.

注意:还要确保没有任何元素覆盖您要查找的对象。

【讨论】:

    【解决方案2】:

    要定位所需的元素,您需要为 elementToBeClickable 诱导 WebDriverWait,您可以使用以下任一解决方案:

    • cssSelector:

      WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.slds-context-bar__label-action.dndItem[href='/lightning/o/Acq_Prospect__c/home']")));
      
    • xpath:

      WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='slds-context-bar__label-action dndItem' and @href='/lightning/o/Acq_Prospect__c/home']")))
      

    【讨论】:

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