当前位置: 首页>>代码示例>>Java>>正文


Java StaleElementReferenceException类代码示例

本文整理汇总了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
			}
		}
	}
}
 
开发者ID:saiscode,项目名称:kheera,代码行数:33,代码来源:PageObject.java

示例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;
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:24,代码来源:AemDialog.java

示例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);
        }
    }
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:21,代码来源:SelectImpl.java

示例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)
	{
	}
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:20,代码来源:TargetElementMark.java

示例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);
    }
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:29,代码来源:RobustElementFactory.java

示例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";
        }
    };
    
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:27,代码来源:RobustElementFactory.java

示例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";
        }
    };
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:29,代码来源:ComponentContainer.java

示例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;
        }
    };

}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:26,代码来源:Coordinators.java

示例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;
        }
    };

}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:27,代码来源:Coordinators.java

示例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;
        }
    };
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:27,代码来源:Coordinators.java

示例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());
		}
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:17,代码来源:DriverUtil.java

示例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;
  });
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:20,代码来源:ConfirmationWindow.java

示例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;
    }
  };
}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:21,代码来源:WaitForDynamicRedraw.java

示例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);
	}
}
 
开发者ID:qmetry,项目名称:qaf,代码行数:26,代码来源:QAFExtendedWebElement.java

示例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;
}
 
开发者ID:opencharles,项目名称:charles,代码行数:21,代码来源:LiveWebPage.java


注:本文中的org.openqa.selenium.StaleElementReferenceException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。