【问题标题】:IE Webdriver pageSource is not refreshing after chnage in page due to javaScript由于javascript,IE Webdriver页面源在页面更改后不刷新
【发布时间】:2016-08-04 21:23:27
【问题描述】:

我正在尝试在 C# 中使用 Selenium 自动化 Web 应用程序,
在主页上,我点击了指向另一个页面的链接。 然后我使用以下代码切换到这个新页面
string parent = webDriver.CurrentWindowHandle; while (webDriver.WindowHandles.Count <= 1) ; // wait for new tab foreach (string handle in webDriver.WindowHandles) { if (handle != parent) { webDriver.SwitchTo().Window(handle); break; } }
这个新页面只有两个链接(用于选择用户角色)
单击第二个链接后,整个页面由 javascipt 更改,并且在同一页面上加载新数据
但是,即使页面已更改,webdriver 仍返回相同的 pageSource(具有 2 个链接的页面)
浏览器正确给出了更改页面的标题
我在文档中读到 IE webdriver 并不总是返回最新的 pageSource
考虑到这一点,只有页面源不正确,驱动程序正在处理我期望的已更改页面
所以我使用
webDriver.FindElements(By.XPath(//a); 做了一个小测试 但它没有给出来自更改页面的标签,而是给出了来自具有两个选择链接的页面的标签。
为什么驱动程序没有返回最新的标签?
我被困在这个问题上,我将非常感谢任何帮助..
提前谢谢!!

【问题讨论】:

    标签: javascript c# selenium internet-explorer-8


    【解决方案1】:

    在获取页面源之前,我会等待指示页面已完全加载的元素:

    WebDriverWait wait = new WebDriverWait(driver, 20);
    
    // switch to the next window
    String main_handle = driver.getWindowHandle();
    wait.until((WebDriver drv) -> {
        for (String handle : drv.getWindowHandles()) {
            if (handle != main_handle) {
                drv.switchTo().window(handle);
                return true;
            }
        }
        return false;
    });
    
    // wait for an element which presence indicates that the page is loaded
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("...")));
    
    // get the page source
    String page_source = driver.getPageSource();
    

    【讨论】:

      猜你喜欢
      • 2019-02-12
      • 1970-01-01
      • 2010-12-26
      • 2019-05-07
      • 2019-06-03
      • 2011-06-01
      • 2012-02-08
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多