2

I'm using PhantomJS as a Selenium webdriver, and I have an in-memory string of a webpage.

How can I load the string into PhantomJS akin to what would happen if I did driver.get()?

I've looked all over but can't find anything like this short of writing a file to disk and GETing that. But that feels a little crazy.

1 Answer 1

9

Did you mean something like this by Data URI scheme?

demo_page = '''
    data:text/html,
    <!doctype html>

    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Test "How to load up PhantomJS with a Python string"</title>
    </head>

    <body>
        <a href="http://stackoverflow.com/q/24834838/1177636">How to load up PhantomJS with a Python string</a>
    </body>
    </html>
'''

driver = webdriver.PhantomJS()
driver.get(demo_page)

driver.save_screenshot('screenshot.png')
driver.quit()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.