English 中文(简体)
网络司机没有可靠地点击链接或 but子
原标题:WebDriver does not reliably click links or buttons

我一直在竭力争取网络司机点击一个 but子或可靠地连接起来,但我不想合作。 我尝试了不同的方法,从确定暗中的时间,到以下的法典,即可以点击和等待要素的出现。

在互联网上发现了以下几处密码,我最接近的是可靠地带上了 but子或连接点击。 除此以外,在我的夜间退步测试期间处决时,它的工作方式并不相同。

是否有任何人知道在浏览器中点子或连接另一个方法? 或者,我应该使用Selenium 1,而不是网络驱动器,因为它太新,无法可靠地加以利用。

public void waitAndClick(WebDriver driver, By by) {
    WebDriverWait wait = new WebDriverWait(driver, 10000, 2000);
    Function<WebDriver, Boolean> waitForElement = new waitForElement(by);
    wait.until(waitForElement);

    Actions builder = new Actions(driver);
    builder.click(driver.findElement(by))
            .perform();
}

private class waitForElement implements Function<WebDriver, Boolean> {
    private final By by;

    private String text = null;

    public waitForElement(By by) {
        this.by = by;
    }

    public waitForElement(By by, String text) {
        this.by = by;
        this.text = text;
    }

    @Override
    public Boolean apply(WebDriver from) {
        if (this.text != null) {
            for (WebElement e : from.findElements(this.by)) {
                if (e.getText().equals(this.text)) {
                    return Boolean.TRUE;
                }
            }

            return Boolean.FALSE;
        } else {
            try {
                driver.switchTo().defaultContent().switchTo().frame("top");
                from.findElement(this.by);
            } catch (Exception e) {
                logger.error("Unable to find "" + this.by.toString() + "". Retrying....");
                return Boolean.FALSE;
            }
            logger.info("Found "" + this.by.toString() + "".");
            return Boolean.TRUE;
        }
    }
}

Eclipse De:

16:07:08,109 INFO  WebDriverUtility: apply Found "By.linkText: Classes".
16:07:10,514 INFO  WebDriverUtility: apply Found "By.linkText: Reports".
16:07:17,028 ERROR WebDriverUtility: apply Unable to find "By.linkText: Users". Retrying....
16:07:26,369 INFO  WebDriverUtility: apply Found "By.linkText: Users".
16:07:38,272 ERROR WebDriverUtility: apply Unable to find "By.linkText: System". Retrying....
16:07:41,334 INFO  WebDriverUtility: apply Found "By.linkText: System".
16:07:47,722 ERROR WebDriverUtility: apply Unable to find "By.linkText: Schools". Retrying....
16:07:50,565 INFO  WebDriverUtility: apply Found "By.linkText: Schools".

从Eclipse开出的青少年:

16:14:04,179 INFO  WebDriverUtility: apply Found "By.linkText: Classes".
16:14:04,726 INFO  WebDriverUtility: apply Found "By.linkText: Reports".
16:14:09,771 INFO  PageAPITesting: login org.openqa.selenium.NoSuchElementException: Unable to find element with link text == Reports (WARNING: The server did not provide any stacktrace information)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version:  2.0rc3 , revision:  12536 , time:  2011-06-20 18:19:52 
System info: os.name:  Windows XP , os.arch:  x86 , os.version:  5.1 , java.version:  1.6.0_24 
Driver info: driver.version: RemoteWebDriver
16:14:09,865 INFO  PageAPITesting: login current tabs is Classes
16:14:09,958 INFO  WebDriverUtility: apply Found "By.linkText: Schools".
16:14:10,240 INFO  PageAPITesting: login java.lang.IllegalStateException: Unable to navigate to the ca.schoolspecialty.qa.api.pages.schools.MenuSchoolPage page
问题回答

我看不到任何奇怪的行为。

等到办法,其用意是将适用方法放在职能上,直到它能够收回一些东西或时间外。

有时,如果该要素尚未建立,预计会收到“不Fo”,实际上,如果你在守则中看到:

 while (clock.isNowBefore(end)) {
  try {
    T value = isTrue.apply(driver);

    if (value != null && Boolean.class.equals(value.getClass())) {
      if (Boolean.TRUE.equals(value)) {
        return value;
      }
    } else if (value != null) {
      return value;
    }
  } catch (NotFoundException e) {
    // Common case in many conditions, so swallow here, but be ready to
    // rethrow if it the element never appears.
    lastException = e;
  }
  sleep();

问题在于,你超越了对捕获和记录这一例外的适用,因此,你所看到的是预期的行为,因此,没有其他办法检查是否制造了这个要素,不断要求它。

我本人在《功能生成者守则》中使用:

public static Function<WebDriver, WebElement> presenceOfElementLocated(
        final By locator) {
    return new Function<WebDriver, WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    };
}

很简单,你可以用于任何激光器





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签