[英]Waiting for element visibility instead of page load with Neustar WPM
I am trying to write a Neustar WPM script to measure the time taken from clicking a button to the appearance of a button in a overlay that opens. 我正在尝试编写Neustar WPM脚本,以测量从单击按钮到打开的叠加层中按钮的外观所花费的时间。 The script looks something like below. 该脚本如下所示。
var webDriver = test.openBrowser();
var selenium = webDriver.getSelenium();
webDriver.get('https://www.mywebsite.com');
selenium.waitForPageToLoad(30000);
// Start logging HTTP traffic and timings
test.beginTransaction();
test.beginStep("Open SignUp");
selenium.click("link=Sign Up");
selenium.waitForElementPresent("name=nextStep");
test.endStep();
test.endTransaction();
The problem I am facing is that click does not return immediately and waits for the overlay to completely load. 我面临的问题是单击不会立即返回,而是等待叠加层完全加载。 However I want to stop as soon as desired element is visible. 但是,我想在所需元素可见时立即停止。 How can I ensure that selenium.click return immediately instead of waiting till entire page is loaded. 我如何确保selenium.click立即返回,而不是等到整个页面加载完毕。
you can try using this Java method, 您可以尝试使用此Java方法,
public WebElement waitForVisibilityOfElementLocatedBy(final By locator) { return waitFor(visibilityOfElementLocated(locator)); }
public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) {
return new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver driver) {
try {
return ExpectedConditions.elementIfVisible(ExpectedConditions.findElement(locator, driver));
} catch (StaleElementReferenceException var2) {
return null;
}
}
public String toString() {
return "visibility of element located by " + locator;
}
};
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.