zoukankan      html  css  js  c++  java
  • 【转载】selenium with PhantomJs wait till page fully loaded?

    I use Selenium with Phantomjs, and want to get the page content after the page fully loaded.

    I tried http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp but it seems not working with phantomjs

    Explicit wait:

    using (IWebDriver driver =newPhantomJSDriver()){IWait<IWebDriver> wait =newOpenQA.Selenium.Support.UI.WebDriverWait(driver,TimeSpan.FromSeconds(30.00));
        wait.Until(driver1 =>((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
    
        driver.Navigate().GoToUrl(url);
    
        content = driver.PageSource;
    
        driver.Quit();}

    Another test:

    using (IWebDriver driver =newPhantomJSDriver()){WebDriverWait wait =newWebDriverWait(driver,TimeSpan.FromSeconds(10));
    
        driver.Url= url;IWebElement myDynamicElement = wait.Until<IWebElement>((d)=>{return d.FindElement(By.Id("footer"));// failed because it's not yet loaded full content });
    
        content = driver.PageSource;}

    Or implicit wait:

    using (IWebDriver driver =newPhantomJSDriver()){
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
        driver.Navigate().GoToUrl(url);
    
        content = driver.PageSource;
    
        driver.Quit();}

    The content is still lacking. The only way is to put Thread.Sleep(waitTime); which is not a good solution for this.

    Thanks.

  • 相关阅读:
    MTK Android 源码目录分析
    MTK Android 平台语言支持状态
    开坑了啦啦啦..
    codeforces泛做..
    用介个新的blog咯..
    【UR #5】怎样跑得更快
    【UR #5】怎样提高智商
    【集训队互测2016】消失的源代码
    口胡
    [八省联考2018]劈配
  • 原文地址:https://www.cnblogs.com/c-x-a/p/7994065.html
Copyright © 2011-2022 走看看