Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenide selenium StaleElementReferenceException:在缓存中找不到元素_Java_Selenium_Selenium Webdriver_Automated Tests_Selenide - Fatal编程技术网

Java Selenide selenium StaleElementReferenceException:在缓存中找不到元素

Java Selenide selenium StaleElementReferenceException:在缓存中找不到元素,java,selenium,selenium-webdriver,automated-tests,selenide,Java,Selenium,Selenium Webdriver,Automated Tests,Selenide,我必须打开页面中的所有链接,然后检查是否有文本(“无信息”) 我使用了SelenideV3.5和Selenium v2.53库。但是,我有一个异常“StaleElementReferenceException” 我的代码如下: open(url); WebDriverRunner.clearBrowserCache(); WebDriverRunner.getWebDriver().manage().timeouts().implicitlyWait(3

我必须打开页面中的所有链接,然后检查是否有文本(“无信息”)

我使用了SelenideV3.5和Selenium v2.53库。但是,我有一个异常“StaleElementReferenceException”

我的代码如下:

    open(url);
        WebDriverRunner.clearBrowserCache();

        WebDriverRunner.getWebDriver().manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

        List<WebElement> linksize = WebDriverRunner.getWebDriver().findElements(By.tagName("a"));

        linksCount = linksize.size();
        links = new String[linksCount];
        Common.consoleOutput.printMessage(String.format("Total no of links Available: %d", linksCount));

        for (int i = 0; i < linksCount; i++)
        {
            links[i] = linksize.get(i).getAttribute("href");

        }
        // navigate to each Link on the webpage
        for (int i = 0; i < linksCount; i++) {
            WebDriverRunner.getWebDriver().navigate().to(url_arabic);
            WebElement error = $(Selectors.byText("No info"));
            $(error).shouldNotBe(visible).shouldNotBe(text("No info"));
        }
open(url);
WebDriverRunner.clearBrowserCache();
WebDriverRunner.getWebDriver().manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
List linksize=WebDriverRunner.getWebDriver().findElements(按.tagName(“a”));
LinkScont=linksize.size();
links=新字符串[LinkScont];
Common.consoleOutput.printMessage(String.format(“可用链接总数:%d”,LinkScont));
对于(int i=0;i
您使用web元素包装:

WebElement error = $(Selectors.byText("No info"));
$(error).shouldNotBe(visible).shouldNotBe(text("No info"));
尝试直接使用选择器换行:

$(Selectors.byText("No info")).shouldNotBe(visible).shouldNotBe(text("No info"));

这应该有帮助。我不建议使用
$(WebElement)
,因为selenide执行搜索元素。如果第一次没有找到元素,那么selenium design很难从WebElement中获取正确的选择器。

在我使用以下代码获取链接元素后,它起到了作用:

List<String> links = new ArrayList<>();
        for (SelenideElement link : $$("a"))
            links.add(link.attr("href"));
List links=new ArrayList();
对于(SelenideElement链接:$$(“a”))
links.add(link.attr(“href”);
而不是

        List<WebElement> linksize = WebDriverRunner.getWebDriver().findElements(By.tagName("a"));
List linksize=WebDriverRunner.getWebDriver().findElements(按.tagName(“a”));

谢谢,但firefox 45.0.1仍然无法使用,我从代码中删除了这一部分,但仍然给出了例外。我删除了(int I=0;I