click method
Clicks on an element matching the given selector
Implementation
Future<bool> click(String selector) async {
_checkDisposed();
if (_controller == null) {
throw ScrapingException.validation(
'Browser not initialized',
isRetryable: false,
);
}
try {
// Wait for the element to be present
final elementExists = await waitForElement(selector);
if (!elementExists) {
_log('Element not found: $selector', isError: true);
return false;
}
// Click the element
final result = await _controller!.evaluateJavascript(
source: """
(function() {
const element = document.querySelector('$selector');
if (!element) return false;
element.click();
return true;
})();
""",
);
return result == true;
} catch (e) {
_log('Error clicking element: $e', isError: true);
return false;
}
}