本文整理匯總了Java中org.openqa.selenium.StaleElementReferenceException類的典型用法代碼示例。如果您正苦於以下問題:Java StaleElementReferenceException類的具體用法?Java StaleElementReferenceException怎麽用?Java StaleElementReferenceException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StaleElementReferenceException類屬於org.openqa.selenium包,在下文中一共展示了StaleElementReferenceException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: map
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* 1. map elements of interest to their name
* 2. reload elements from the page every time `map` is called
*
* E.g., Say ELEMENT_LOCATORS=id
* and <input id="username" type="text"></input>
* then nameElementMap will contain "username" => WebElement
*/
@Override
protected void map(AbstractPage p) {
getBys();
List<WebElement> elements = new ArrayList<WebElement>();
for (By by : bys) {
elements.addAll(driver.findElements(by));
}
PageFactory.initElements(driver, this);
String[] tokens = locators.split(",");
for(WebElement w: elements) {
for (String s : tokens) {
try{
String attr = w.getAttribute(s);//throws StaleElementReferenceException
if (attr != null) {
nameElementMap.put(attr, w);
}
}catch(StaleElementReferenceException se){
//ignoring elements which have become stale because
//a stale object shouldn't have to be referenced
//by an automation script
}
}
}
}
示例2: clickDialogFooterButton
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* Clicks button at the bottom of edit Window and expect for dialog to disappear.
*
* @param buttonText button label
* @return Returns this dialog instance.
*/
public AemDialog clickDialogFooterButton(final String buttonText) {
final WebElement footerButton = getFooterButtonWebElement(buttonText);
bobcatWait.withTimeout(Timeouts.BIG).until((ExpectedCondition<Object>) input -> {
try {
footerButton.click();
footerButton.isDisplayed();
return Boolean.FALSE;
} catch (NoSuchElementException | StaleElementReferenceException
| ElementNotVisibleException e) {
LOG.debug("Dialog footer button is not available: {}", e);
return Boolean.TRUE;
}
}, 2);
bobcatWait.withTimeout(Timeouts.MEDIUM).until(CommonExpectedConditions.noAemAjax());
return this;
}
示例3: selectRandom
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
@Override
public void selectRandom() {
int count = 0;
while (count < 5) {
try {
final org.openqa.selenium.support.ui.Select wrapped = wrappedSelect();
int optionsSize = getOptions().size();
if (optionsSize > 1) {
int optionIndex = nextInt(optionsSize);
while (getOptions().get(optionIndex).isSelected()) {
optionIndex = nextInt(optionsSize);
}
wrapped.selectByIndex(optionIndex);
}
break;
} catch (StaleElementReferenceException e) {
TestUtils.waitForSomeTime(1000, EXPLANATION_MESSAGE_FOR_WAIT);
}
}
}
示例4: mark
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
@Override
public void mark(WebElement ele, File file) throws IOException
{
BufferedImage bufImg = ImageIO.read(file);
try
{
WebElement webEle = (WebElement) ele;
Point loc = webEle.getLocation();
Dimension size = webEle.getSize();
Graphics2D g = bufImg.createGraphics();
g.setColor(Color.red);
g.drawRect(loc.getX(), loc.getY(), size.getWidth(), size.getHeight());
}
catch(StaleElementReferenceException se)
{
}
}
示例5: intercept
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* This is the method that intercepts component container methods in "enhanced" model objects.
*
* @param obj "enhanced" object upon which the method was invoked
* @param method {@link Method} object for the invoked method
* @param args method invocation arguments
* @return {@code anything} (the result of invoking the intercepted method)
* @throws Exception {@code anything} (exception thrown by the intercepted method)
*/
@RuntimeType
@BindingPriority(Integer.MAX_VALUE)
public Object intercept(@This Object obj, @Origin Method method, @AllArguments Object[] args) throws Exception
{
try {
return method.invoke(getWrappedElement(), args);
} catch (InvocationTargetException ite) {
Throwable t = ite.getCause();
if (t instanceof StaleElementReferenceException) {
try {
StaleElementReferenceException sere = (StaleElementReferenceException) t;
return method.invoke(refreshReference(sere).getWrappedElement(), args);
} catch (NullPointerException npe) {
throw deferredException();
}
}
throw UncheckedThrow.throwUnchecked(t);
}
}
示例6: referenceIsRefreshed
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* Returns a 'wait' proxy that refreshes the wrapped reference of the specified robust element.
*
* @param wrapper robust element wrapper
* @return wrapped element reference (refreshed)
*/
private static Coordinator<RobustElementWrapper> referenceIsRefreshed(final RobustElementWrapper wrapper) {
return new Coordinator<RobustElementWrapper>() {
@Override
public RobustElementWrapper apply(SearchContext context) {
try {
return acquireReference(wrapper);
} catch (StaleElementReferenceException e) {
((WrapsContext) context).refreshContext(((WrapsContext) context).acquiredAt());
return acquireReference(wrapper);
}
}
@Override
public String toString() {
return "element reference to be refreshed";
}
};
}
示例7: contextIsSwitched
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* Returns a 'wait' proxy that switches focus to the specified context
*
* @param context search context on which to focus
* @return target search context
*/
static Coordinator<SearchContext> contextIsSwitched(final ComponentContainer context) {
return new Coordinator<SearchContext>() {
@Override
public SearchContext apply(SearchContext ignore) {
if (context.parent != null) {
context.parent.switchTo();
}
try {
return context.switchToContext();
} catch (StaleElementReferenceException e) {
return context.refreshContext(context.acquiredAt());
}
}
@Override
public String toString() {
return "context to be switched";
}
};
}
示例8: visibilityOfElementLocated
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* Returns a 'wait' proxy that determines if the first element matched by the specified locator is visible
*
* @param locator web element locator
* @return web element reference; 'null' if the indicated element is absent or hidden
*/
public static Coordinator<WebElement> visibilityOfElementLocated(final By locator) {
return new Coordinator<WebElement>() {
@Override
public WebElement apply(SearchContext context) {
try {
return elementIfVisible(context.findElement(locator));
} catch (StaleElementReferenceException e) {
return null;
}
}
@Override
public String toString() {
return "visibility of element located by " + locator;
}
};
}
示例9: visibilityOfAnyElementLocated
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* Returns a 'wait' proxy that determines if any element matched by the specified locator is visible
*
* @param locator web element locator
* @return web element reference; 'null' if no matching elements are visible
*/
public static Coordinator<WebElement> visibilityOfAnyElementLocated(final By locator) {
return new Coordinator<WebElement>() {
@Override
public WebElement apply(SearchContext context) {
try {
List<WebElement> visible = context.findElements(locator);
return (WebDriverUtils.filterHidden(visible)) ? null : visible.get(0);
} catch (StaleElementReferenceException e) {
return null;
}
}
@Override
public String toString() {
return "visibility of element located by " + locator;
}
};
}
示例10: invisibilityOfElementLocated
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
/**
* Returns a 'wait' proxy that determines if an element is either hidden or non-existent.
*
* @param locator web element locator
* @return 'true' if the element is hidden or non-existent; otherwise 'false'
*/
public static Coordinator<Boolean> invisibilityOfElementLocated(final By locator) {
return new Coordinator<Boolean>() {
@Override
public Boolean apply(SearchContext context) {
try {
return !(context.findElement(locator).isDisplayed());
} catch (NoSuchElementException | StaleElementReferenceException e) {
// NoSuchElementException: The element is not present in DOM.
// StaleElementReferenceException: Implies that element no longer exists in the DOM.
return true;
}
}
@Override
public String toString() {
return "element to no longer be visible: " + locator;
}
};
}
示例11: waitFor
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
public static void waitFor(WebDriver driver, long timeout, By... elements) throws TimeoutException, InterruptedException {
try {
WaitUtil.waitFor(() -> elementsPresent(driver, elements), null, 1000L, timeout);
} catch (TimeoutException ex) {
try {
for (By element : elements) {
WebElement webElement = driver.findElement(element);
if (!webElement.isDisplayed()) {
throw new TimeoutException("Timeout exception during waiting for web element: " + webElement.getText());
}
}
} catch (NoSuchElementException | StaleElementReferenceException x) {
throw new TimeoutException("Timeout exception during waiting for web element: " + x.getMessage());
}
}
}
示例12: clickButton
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
private void clickButton(final String buttonLabel) {
final WebElement button =
bobcatWait.withTimeout(Timeouts.BIG).until(input -> window.findElement(
By.xpath(String.format(BUTTON_XPATH_FORMATTED, buttonLabel))));
bobcatWait.withTimeout(Timeouts.MEDIUM).until(ExpectedConditions.elementToBeClickable(button));
bobcatWait.withTimeout(Timeouts.BIG).until(input -> {
boolean confirmationWindowClosed;
try {
button.click();
confirmationWindowClosed = !window.isDisplayed();
} catch (NoSuchElementException | StaleElementReferenceException e) {
LOG.debug("Confirmation window is not available", e);
confirmationWindowClosed = true;
}
return confirmationWindowClosed;
});
}
示例13: dynamicRedrawFinishes
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
private ExpectedCondition<Boolean> dynamicRedrawFinishes(final WebElement element) {
return new ExpectedCondition<Boolean>() {
int retries = 3;
@Override
public Boolean apply(WebDriver ignored) {
try {
element.isEnabled();
} catch (StaleElementReferenceException expected) {
if (retries > 0) {
retries--;
dynamicRedrawFinishes(element);
} else {
throw expected;
}
}
return true;
}
};
}
示例14: onFailure
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onFailure(QAFExtendedWebElement element, CommandTracker commandTracker) {
commandTracker.setStage(Stage.executingOnFailure);
commandTracker.setEndTime(System.currentTimeMillis());
if (commandTracker.getException() instanceof StaleElementReferenceException) {
logger.warn(commandTracker.getException().getMessage());
element.setId("-1");
Map parameters = commandTracker.getParameters();
parameters.put("id", element.getId());
commandTracker.setException(null);
commandTracker.setStage(Stage.executingMethod);
element.execute(commandTracker.command, parameters);
commandTracker.setEndTime(System.currentTimeMillis());
}
for (QAFWebElementCommandListener listener : listners) {
// whether handled previous listener
if (!commandTracker.hasException()) {
break;
}
logger.debug("Executing listener " + listener.getClass().getName());
listener.onFailure(element, commandTracker);
}
}
示例15: getLinks
import org.openqa.selenium.StaleElementReferenceException; //導入依賴的package包/類
public Set<Link> getLinks() {
Set<Link> links = new HashSet<Link>();
String currentLoc = this.getUrl();
List<WebElement> anchors = this.driver
.findElements(By.tagName("a"));
for(WebElement a : anchors) {
try {
Link l = new Link(a.getText(), a.getAttribute("href"));
if(l.valid(currentLoc)) {
links.add(l);
}
} catch (final StaleElementReferenceException sre) {
//stale link, ignore it
//More here:
//http://www.seleniumhq.org/exceptions/stale_element_reference.jsp
}
}
return links;
}