未找到C#Selenium PhantomJS元素

时间:2017-06-18 14:01:47

标签: c# selenium phantomjs

我尝试使用Selenium和PhantomJS从this website获取整页来源,但它无法获得整页来源,只有这样:

<!DOCTYPE html><html class="uiSecureRoutePopup uiProductShipOutIn uiLanguageChooser uiShippingAvgPrepTime uiProductPreorder uiProductPreorderCrossborderSupport uiOrderArrangePickupCanEdit orderAftership uiOrderMassShipOpenToAllUsers uiOrderMassShipAutoConsignment uiOrderFilterInToShip uiMassShipPoslajuIntegrated uiShopImportRuten uiIncomeExportAddVoucher massUploadShipDays uiMassUpdateOpenToAllUsers embeddedChat uiPaymentServices uiUnlinkPaymentService uiBankAccountAllowLastAccountDeletion uiLogisticsPoslajuPickupWhitelist uiMassUpdateDaysToShip uiOTPSecurity uiOTPSecurityChangePassword uiOTPSecurityChangeBank uiOTPSecurityChangePhone closeOfflinePayment allowTurnOffDefaultOnlyChannel uiWholesale productLevelLogistics productLevelLogisticsMassUpdate uiAdsPortal uiTHDisabledLogisticsHidePrice uiGoJekLogistics uiNumericalWalletLimit uiAdsUseTimestamps uiWalletPaymentTransactionFilter uiRatingReply uiPLSShopDefaultLogistics uiBeatAdBlock uiVoucher uiAdsReportingItemSoldGMV uiProductAttributeQualityControl uiGoJekErrorMessageImprovements touchevents no-flexbox"><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <base href="/">
    <meta name="description" content="">
    <meta name="viewport" content="width=1200">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">

<meta name="ads-portal/config/environment" content="%7B%22modulePrefix%22%3A%22ads-portal%22%2C%22environment%22%3A%22production%22%2C%22dependencyImport%22%3A%7B%22helper%22%3A%5B%22inline-svg%22%2C%22cdn-file%22%2C%22validator%22%2C%22feature-flag%22%5D%2C%22component%22%3A%5B%22shopee-price%22%2C%22product/basic-item%22%2C%22shopee-dropdown-period-picker%22%2C%22no-result%22%5D%7D%2C%22shopeeEmberCommon%22%3A%7B%22country%22%3A%22sg%22%7D%7D">
    <link rel="stylesheet" href="https://cdn.shopee.co.id/shopee/shopee-seller-static-live-id/assets/vendor-61977354650bc2f42cdf2a723a05b1bd.css" integrity="sha256-86Gd79yhCZrS0YoMKNMnRUgHp5qyLcaxP2iIUcCfBoE= sha512-CIA0hfIykimLMaTEekxDlvlg3NzcC+Vb7Lb0FNg/bwZssfxqQlgiNA9cACwOqhPwcNlCvvmcgeclvVYtsIUg1w==" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.shopee.co.id/shopee/shopee-seller-static-live-id/assets/seller-2cd97775ac239c622e92d6b785b6173d.css">
    <meta name="seller/config/asset-manifest" content="%7B%22bundles%22%3A%7B%22ads-portal%22%3A%7B%22assets%22%3A%5B%7B%22uri%22%3A%22https%3A%2F%2Fcdn.shopee.co.id%2Fshopee%2Fshopee-seller-static-live-id%2Fengines-dist%2Fads-portal%2Fassets%2Fengine-vendor-f629d8e9a5b174e0b10379b61b1d6a89.css%22%2C%22type%22%3A%22css%22%7D%2C%7B%22uri%22%3A%22https%3A%2F%2Fcdn.shopee.co.id%2Fshopee%2Fshopee-seller-static-live-id%2Fengines-dist%2Fads-portal%2Fassets%2Fengine-vendor-edf7ea3ec3561c7f06b64ecb02eaa792.js%22%2C%22type%22%3A%22js%22%7D%2C%7B%22uri%22%3A%22https%3A%2F%2Fcdn.shopee.co.id%2Fshopee%2Fshopee-seller-static-live-id%2Fengines-dist%2Fads-portal%2Fassets%2Fengine-d3bc5a4128a2ad34710eb812a7d375b0.css%22%2C%22type%22%3A%22css%22%7D%2C%7B%22uri%22%3A%22https%3A%2F%2Fcdn.shopee.co.id%2Fshopee%2Fshopee-seller-static-live-id%2Fengines-dist%2Fads-portal%2Fassets%2Fengine-77fa2ffdad40c9e68fb501548252ec1c.js%22%2C%22type%22%3A%22js%22%7D%5D%7D%7D%7D">
    <link rel="manifest" href="/manifest.json">
  <script src="https://connect.facebook.net/en_US/sdk.js?_=1497786568487"></script></head>
  <body>

    <div id="shopee-powerseller-root" style="height:100%; min-height:100%;" class="ember-application"></div>
    <div id="shopee-chat-embedded" style="z-index: 99999; position: fixed; right: 70px; bottom: 0;"></div>

    <script src="https://cdn.shopee.co.id/shopee/shopee-seller-static-live-id/assets/vendor-b3476ceab28d140e360d81006f6350c4.js"></script>
    <script src="//cdn.ravenjs.com/3.12.1/raven.min.js" integrity="sha384-Xsu9Kcp/8TUx5byUpQAwCO2ByWnABezqEqRw4j5RwiAF9dzn3/9lazwDT1RDg5Pe" crossorigin="anonymous"></script>
    <script src="https://cdn.shopee.co.id/shopee/shopee-seller-static-live-id/assets/seller-0f71e00ef5525918738a48cf55273001.js"></script>

    <audio class="beep-sound" preload="none">
      <source src="https://cdn.shopee.co.id/shopee/shopee-seller-static-live-id/sound/notification.mp3" type="audio/mpeg">
    </audio>
</body></html>

我的代码:

public static Func<IWebDriver, IWebElement> ElementToBeClickable(By locator)
    {
        return driver =>
        {
            var element = driver.FindElement(locator);
            return (element != null && element.Displayed && element.Enabled) ? element : null;
        };
    }

            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
             service.SslProtocol = "tlsv1";
             service.WebSecurity = false;
             service.IgnoreSslErrors = true;

             var driver = new PhantomJSDriver(service);
            driver.Navigate().GoToUrl("https://seller.shopee.co.id/account/signin?next=index.index&params=%5B%5D");

        //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(40));

        var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[contains(@placeholder, 'Username')]")));
        Console.WriteLine(driver.PageSource);

输出

  

[错误 - 2017-06-18T13:54:11.563Z] WebElementLocator - _handleLocateCommand - 未找到元素:GAVE UP。搜索停止时间:1497794051508

如何解决这个问题?

0 个答案:

没有答案