Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

If PhantomJS appears to freeze after a click, first identify which operation is still waiting: a network resource, a page load, a script, or a Selenium condition. Put a finite timeout on that operation, log page errors and requests, and wait for the specific DOM change the click should cause. PhantomJS development is suspended, so for a maintained Python workflow, plan to move the test to a browser Selenium currently supports.

Find the exact operation that hangs

A click itself is not always the cause. The browser may be waiting for a request that never finishes, Selenium may be waiting for a page-load event, or the expected result may never appear because page JavaScript failed. Note the URL, the exact command after which execution stops, the expected result, and whether the browser window remains responsive.

Check the installed runtime with phantomjs --version, and record the operating-system version. The PhantomJS project says its development is suspended until further notice: PhantomJS. Its issue-reporting guidance asks for reproducible steps, actual and expected behavior, and a reduced test case: PhantomJS issue-reporting guidance.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • If execution stops at navigation or a request, investigate resource and page-load timeouts.
  • If a click returns but the next lookup or wait never succeeds, check whether the page reached the intended state and whether the wait has a deadline.
  • If the page behaves unexpectedly, log JavaScript errors and network activity before changing timeouts.

Bound PhantomJS resource waits and log failures

For code that uses PhantomJS’s page API, set page.settings.resourceTimeout in milliseconds before the first page.open. The setting reference documents onResourceTimeout as the timeout callback and notes that changing settings after the initial open does not affect that load: WebPage settings.

var page = require('webpage').create();

page.settings.resourceTimeout = 15000;

page.onResourceRequested = function (requestData, networkRequest) {
  console.log('Request: ' + requestData.method + ' ' + requestData.url);
};

page.onResourceTimeout = function (request) {
  console.log('Resource timed out: ' + request.url);
  console.log('Error code: ' + request.errorCode + '; description: ' + request.errorString);
};

page.onError = function (message, trace) {
  console.log('Page JavaScript error: ' + message);
  trace.forEach(function (item) {
    console.log('  ' + item.file + ':' + item.line);
  });
};

page.open('https://example.com', function (status) {
  console.log('Initial open status: ' + status);
  // Perform or trigger the interaction here, then verify its expected result.
  phantom.exit();
});

Adjust the example’s URL and interaction to reproduce the failure. The timeout only limits individual resource waits; it does not guarantee that an application interaction succeeded. Use the timeout callback and request log to identify what failed, then confirm the intended state separately. PhantomJS documents onResourceRequested and onError in its troubleshooting reference: PhantomJS troubleshooting.

Set the correct Selenium timeout in Python

Selenium exposes distinct implicit, page-load, and script timeouts. They govern different operations: element location, navigation completion, and asynchronous script execution, respectively. Set the page and script limits deliberately, and keep implicit waits at zero or small when using explicit waits so their combined timing is predictable. The current Python API documents the timeout categories: Selenium Python WebDriver API.

Here is a complete pattern for a Selenium test using a supported browser. Replace the URL, selectors, and expected text with those for the page under test:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners
  • Language: english
  • Book - automate the boring stuff with python, 2nd edition: practical programming for total beginners
  • It is made up of premium quality material.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(0)
driver.set_page_load_timeout(30)
driver.set_script_timeout(15)

try:
    driver.get("https://example.com")
    wait = WebDriverWait(driver, 15)

    button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#run")))
    button.click()

    result = wait.until(EC.visibility_of_element_located(
        (By.CSS_SELECTOR, "#result")
    ))
    wait.until(lambda d: result.text.strip() != "")
    print("Result:", result.text)
except TimeoutException as exc:
    print("Timed out waiting for navigation or the expected page state:", exc)
    print("Current URL:", driver.current_url)
    print("Page title:", driver.title)
    print("Page source excerpt:", driver.page_source[:2000])
finally:
    driver.quit()

Selenium’s browser-options documentation describes defaults of 30,000 milliseconds for script timeout and 300,000 milliseconds for page-load timeout; these are documented defaults, not necessarily sensible limits for your application. Set explicit values as above rather than relying on defaults: Selenium browser options.

Wait for the result, not an arbitrary delay

After clicking, identify what success looks like and wait for that condition. Common choices include a result becoming visible, text becoming non-empty, a spinner disappearing, or the URL changing. A fixed sleep can sometimes help diagnose a timing issue, but it is not a reliable correctness check: it may be unnecessarily long on a fast run and too short on a slow one.

  1. Locate the clickable control and wait until it is interactable.
  2. Click it once.
  3. Wait with a finite deadline for the expected result condition.
  4. On timeout, capture the current URL, title, relevant page text, and any request or JavaScript-error logs.

Use a condition that distinguishes success from merely having an element in the DOM. For example, presence is weaker than visibility, and visibility is weaker than the result text being populated. If the page replaces the result node after the click, re-locate it inside the wait rather than relying on an old element reference.

Make the hang observable

When you reproduce the issue, keep the case small: one URL, one interaction, and one expected state. PhantomJS request logging can reveal an asset or API call that never returns; its resource-timeout callback reports timed-out resources. The page error callback can reveal a JavaScript exception that prevented the expected state. These are documented callbacks, not assumptions about what the failing page is doing.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For Selenium, catch TimeoutException at the operation boundary and log the current URL, title, and a useful excerpt of the DOM. Keep separate logs for navigation and post-click conditions so you can tell whether the driver failed to load the page or the application failed to produce the result. Avoid swallowing the exception and continuing as though the interaction succeeded.

Common causes and fixes

Symptom Likely cause What to do
The test stops during or just after navigation A request or page-load event is still pending. Set a finite resource timeout before PhantomJS’s first page.open, or set Selenium’s page-load timeout. Use request logs to identify slow or stalled resources.
The click returns, but a result wait expires The click did not trigger the expected state, the selector is wrong, or the application did not finish its update. Inspect the DOM and URL at timeout; wait for the actual result condition and verify the selector against the rendered page.
The expected result never appears and the console is quiet Page-side JavaScript may have thrown or taken a different code path. Add PhantomJS onError logging and capture the message and stack trace. Reproduce with one interaction.
Timeouts vary or compound unpredictably Implicit waits and explicit waits are being mixed, or several timeout types are mistaken for one another. Use a zero or small implicit wait with explicit conditions, and set navigation and script limits separately.
The same script fails across unrelated modern sites The suspended PhantomJS runtime may be incompatible with current page behavior. Port the workflow to a supported Selenium browser and replace PhantomJS-specific capabilities.

Migrate from PhantomJS for a maintained test

PhantomJS development is suspended. Selenium’s current Python documentation lists Chrome, Edge, Firefox, Safari, WebKitGTK, and WPEWebKit among supported browsers and describes Selenium Manager for driver setup; PhantomJS is not listed there: Selenium supported browsers. For a durable workflow, move the test to one of those documented browsers, remove PhantomJS-specific capabilities, and retain the bounded, condition-based wait pattern.

Migration is not always a one-line driver substitution. Review browser options, any PhantomJS-specific APIs or capabilities, selectors that depended on old rendering behavior, and timing assumptions. Run the reduced test first, then expand coverage. Selenium Manager is documented as part of Selenium’s driver setup guidance, but exact installation behavior can depend on the environment and browser availability.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a screenshot rather than an interactive Selenium test, ScreenshotNeo provides a website screenshot API and MCP server. A GET request returns a PNG, JPEG, WebP, or PDF. It is not a replacement for testing arbitrary click-driven behavior; use the local browser approach above when the test must interact with the page and assert application state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

One-call cURL example, with the API documentation at ScreenshotNeo docs:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes 60+ known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers identifying the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots per month without a card.

FAQ

Does a longer timeout fix a PhantomJS hang?

Only if the operation is legitimately slower than its current limit. A longer deadline cannot fix a request that never completes or a result condition that will never become true; log the failure and wait for the intended state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I keep using PhantomJS for an existing script?

You can investigate and bound its waits, but the project’s suspended development means it is not the durable choice for new or maintained browser automation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.