Troubleshooting

Troubleshooting

Fixes for the problems that come up most often with Aspose.HTML FOSS for Python, grouped by layer.

Styles and the Cascade

A stylesheet rule has no effect. The sheet must be attached with Document.attach_style_sheet() before Element.get_computed_style() is called. Unattached sheets never participate in the cascade.

An inline declaration loses to a stylesheet rule. Author rules marked !important outrank non-important inline declarations. Check with CSSStyleDeclaration.get_property_priority().

Two rules tie and the “wrong” one wins. Equal-specificity ties resolve by rule order — later rules win. Compare tuples with specificity() when in doubt.

An inherited value does not reach a child. Local values always override inherited ones, and not every property inherits. Read the parent’s computed value first to confirm what should flow down.

Parsing and the DOM

Malformed markup parses without an error. Standards behaviour: tree construction defines recovery for every error case. If you need to detect problems, inspect the token stream via Tokenizer.tokenize().

Table content appears outside its table. Foster parenting relocated misplaced table content, exactly as browsers do. Fix the source nesting.

get_element_by_id() returns nothing. The element must carry the id attribute and be attached to that document’s tree.

Encodings

A byte-order mark shows up in decoded text. Use detect_encoding() — it strips BOM bytes from result.text. Manual decoding leaves them in.

Two labels for the same encoding compare unequal. Normalize both with get_canonical_name(); latin1 and iso-8859-1 are both windows-1252 canonically.

Scripts

Evaluation raises ModuleNotFoundError. The script imports a module not present in ModuleRegistry. Register it or treat the error as your sandbox working as intended.

A script failure takes down the pipeline. Catch JSEvaluationError at the evaluation boundary — it is the typed signal for script-side failures.

See Also