简体   繁体   中英

Get injected javascript from a website when testing with Selenium / Protractor

I'm using Selenium / Protractor to test my application's UI and html. I have a <script type="application/ld+json"> that is injected into the sites and I want to grab the contents of this script tag so I can use it for some tests.

An example of the script is below:

<script type="application/ld+json">

    {
        "@context": "http://schema.org",
        "@type": "LocalBusiness",
        "name": "The Best Company Name",
        "image": "https://www.urltowebsite.us/WebContent/Images/Dealer/6/Logo.png?preset=Dealer.Logo",
        "address": {
            "@type": "PostalAddress",
            "streetAddress": "19 North Suite 2 ",
            "addressLocality": "Mobile",
            "addressRegion": "MS",
            "postalCode": "39107",
            "addressCountry": "USA"
        },
        "geo": {
            "@type": "GeoCoordinates",
            "latitude": "32.351923",
            "longitude": "-88.73434"
        },
        "openingHoursSpecification": [{
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": [
                "Monday"
                ],
                "opens": "07:30:00",
                "closes": "17:00:00"
            },
            {
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": [
                "Tuesday"
                ],
                "opens": "07:30:00",
                "closes": "17:00:00"
            },
            {
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": [
                "Wednesday"
                ],
                "opens": "07:30:00",
                "closes": "12:00:00"
            }
        ]
    }
</script>

I'm using Selenium / Protractor to test my application's UI and html. I have a <script type="application/ld+json"> that is injected into the sites and I want to grab the contents of this script tag so I can use it for some tests.

An example of the script is below:

<script type="application/ld+json">

    {
        "@context": "http://schema.org",
        "@type": "LocalBusiness",
        "name": "The Best Company Name",
        "image": "https://www.urltowebsite.us/WebContent/Images/Dealer/6/Logo.png?preset=Dealer.Logo",
        "address": {
            "@type": "PostalAddress",
            "streetAddress": "19 North Suite 2 ",
            "addressLocality": "Mobile",
            "addressRegion": "MS",
            "postalCode": "39107",
            "addressCountry": "USA"
        },
        "geo": {
            "@type": "GeoCoordinates",
            "latitude": "32.351923",
            "longitude": "-88.73434"
        },
        "openingHoursSpecification": [{
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": [
                "Monday"
                ],
                "opens": "07:30:00",
                "closes": "17:00:00"
            },
            {
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": [
                "Tuesday"
                ],
                "opens": "07:30:00",
                "closes": "17:00:00"
            },
            {
                "@type": "OpeningHoursSpecification",
                "dayOfWeek": [
                "Wednesday"
                ],
                "opens": "07:30:00",
                "closes": "12:00:00"
            }
        ]
    }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM