我试着用Selenium在Salesforce上实现自动化。如何等待搜索结果显示在屏幕截图中?方法-1还是方法-2?

//Method-1
public void waitForPageLoadXHR(WebDriver driver) {
new WebDriverWait(driver, 15).until(
driver1 -> ((JavascriptExecutor) driver1).executeScript("return document.readyState").equals("complete"));
}
//Method-2
public void waitForPageLoadXHR(WebDriver driver) {
new WebDriverWait(driver, 15).until(
driver1 -> ((JavascriptExecutor) driver1).executeScript("return jQuery.active == 0"));
}更新:这里是的一个表示。很抱歉,由于遵从性问题,我无法发布实际的HTML。< and >是我的文本框,搜索结果是< li >s‘。< li >以我键入的方式动态显示。

发布于 2020-04-01 17:40:19
(1)我看到您正在搜索一个帐户,并在Salesforce页面的全局搜索字段上发送字符串。我这里的第一个建议是‘不要复制和粘贴’您的帐户(或任何名称)直接在这里。Salesforce照明是一个沉重的场所,比通常的地点花费更多的时间。所以你能做的是-一个字一个字地给你,少等。我知道这个技巧,你可能不喜欢,但它对我是100% -见下面的代码:
for (int i = 0; i < value.length(); i++){
char character = value.charAt(i);
String inputCharacterText = new StringBuilder().append(character).toString();
driver.findElement(webElement).sendKeys(inputCharacterText);
Thread.sleep(50);
} (2)你主要问题的解决办法:
TestWait.waitForElementToBeVisible(驱动程序,PageClass.searchAccount(驱动程序));
这是您的WebElement:(由于您正在搜索特定的帐户,然后尝试使用使用xpath的自定义文本-example“//*@-example=‘AccountName’”来使用-example)
public static By searchAccount= By.xpath("You XPATH go here ");
public static By searchAccount(WebDriver driver) {
return searchAccount ;
}请使用下面提到的等待方法,它对我来说非常有用:
类是"TestWait“,您在类中定义了下面的方法
公共静态布尔waitForElementToBeVisible(WebDriver驱动程序,由expectedElement提供){
boolean webElement = false;
logger.info("Executing waitForElementToBeVisible for page element");
try {
logger.info("Waiting for web element " + expectedElement + " with fluent wait");
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
Wait<WebDriver> wait = new
FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(45))
.pollingEvery(Duration.ofMillis(200))
.ignoring(org.openqa.selenium.NoSuchElementException.class,org.openqa.
selenium.StaleElementReferenceException.class)
.ignoring(org.openqa.selenium.ElementNotVisibleException.class);
wait.until(ExpectedConditions.visibilityOfElementLocated(expectedElement));
webElement = true;
} catch (Exception e) {
logger.error(expectedElement + " : Not found the element on Page");
webElement = false;
Assert.fail("WebElement is not visible");
} finally {
driver.manage().timeouts().implicitlyWait(TestConstant.ImplicitWaitTime, TimeUnit.SECONDS);
}
return webElement;
}https://stackoverflow.com/questions/60511993
复制相似问题