[英]Unable to Locate an element for Salesforce Lightning
Technology: 技术:
Html: 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>
Code Trials: 代码试用:
driver.findElement(By.xpath("//a[@title='Acq Prospects']"));
driver.findElement(By.linkText("Acq Prospect"));
Error: 错误:
Unable to find an element
You simply need to wait object to be visible. 您只需要等待对象可见即可。 You can use the following code;
您可以使用以下代码;
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.Until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='Acq Prospects']")));
For more informations; 有关更多信息; link .
链接 。
Note: Also ensure that there is no any element that overlay your object which you are trying to find. 注意:还请确保没有任何元素覆盖您要查找的对象。
To locate the desired element you need to induce WebDriverWait for the elementToBeClickable and you can use either of the following solutions: 要找到所需的元素,您需要为elementToBeClickable引入WebDriverWait ,并且可以使用以下解决方案之一:
cssSelector
: 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
: 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']")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.