Jquery Selenium webdriver等待后台XHR请求
我正在尝试使用Selenium在Salesforce上实现自动化。如何等待搜索结果显示在屏幕截图中?方法1还是方法2 更新:这里是HTML的一个表示形式。很抱歉,由于法规遵从性问题,我无法发布实际的HTML。是我的文本框,搜索结果是Jquery Selenium webdriver等待后台XHR请求,jquery,ajax,selenium,xmlhttprequest,webdriver,Jquery,Ajax,Selenium,Xmlhttprequest,Webdriver,我正在尝试使用Selenium在Salesforce上实现自动化。如何等待搜索结果显示在屏幕截图中?方法1还是方法2 更新:这里是HTML的一个表示形式。很抱歉,由于法规遵从性问题,我无法发布实际的HTML。是我的文本框,搜索结果是s'。在I键入时动态显示 (1)我看到您正在Salesforce页面的全局搜索字段中搜索帐户并发送字符串。我的第一个建议是“不要直接在这里复制和粘贴”您的帐户(或任何名称)。Salesforce Lighting是一个繁重的站点,比普通站点花费更多的时间。所以你能做
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);
}
请使用下面提到的等待方法,它对我来说非常有效:
类是“TestWait”,您在类中定义了下面的方法
公共静态布尔WaitForElementToBevible(WebDriver驱动程序,按expectedElement){
布尔webElement=false;
info(“为页面元素执行WaitForElementToBevicible”);
试一试{
info(“正在等待web元素”+expectedElement+“使用流畅的等待”);
driver.manage().timeouts().implicitlyWait(0,TimeUnit.SECONDS);
等待=新建
FluentWait(驱动程序)
.withTimeout(持续时间秒(45))
.pollingEvery(持续时间:百万(200))
.ignoring(org.openqa.selenium.NoSuchElementException.class,org.openqa)。
selenium.StaleElementReferenceException.class)
.ignoring(org.openqa.selenium.ElementNotVisibleException.class);
等待.直到(ExpectedConditions.visibilityOfElementLocated(expectedElement));
webElement=true;
}捕获(例外e){
logger.error(expectedElement+“:在第页上找不到元素”);
webElement=false;
Assert.fail(“WebElement不可见”);
}最后{
driver.manage().timeouts().implicitlyWait(TestConstant.ImplicitWaitTime,TimeUnit.SECONDS);
}
返回webElement;
}
您是否可以编辑您的问题并添加HTML(或至少一段具有代表性的HTML片段)以自动完成建议?您可能需要等待一个元素出现在自动填充的列表中,而不是试图等待AJAX完成。考虑使用格式化的基于文本的HTML、代码试验和错误堆栈跟踪更新问题。@ DEBANJANB,我已经复制粘贴了我的代码,并用相关的标签标记了问题,以便它是可搜索的。HTML很长,不会给问题增加任何附加值,更不用说影响你发布的链接中提到的搜索能力了。但是,我知道它可能会影响屏幕阅读器的用户,但很抱歉,我仍然无法发布实际的HTML,因为它包含我的客户端的可识别信息。
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);
}
public static By searchAccount= By.xpath("You XPATH go here ");
public static By searchAccount(WebDriver driver) {
return searchAccount ;
}
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;
}