private async Task <(decimal x, decimal y)> ClickablePointAsync() { GetContentQuadsResponse result = null; var contentQuadsTask = Client.SendAsync <GetContentQuadsResponse>("DOM.getContentQuads", new DomGetContentQuadsRequest { ObjectId = RemoteObject.ObjectId }); var layoutTask = Client.SendAsync <PageGetLayoutMetricsResponse>("Page.getLayoutMetrics"); try { await Task.WhenAll(contentQuadsTask, layoutTask).ConfigureAwait(false); result = contentQuadsTask.Result; } catch (Exception ex) { _logger.LogError(ex, "Unable to get content quads"); } if (result == null || result.Quads.Length == 0) { throw new PuppeteerException("Node is either not visible or not an HTMLElement"); } // Filter out quads that have too small area to click into. var quads = result.Quads .Select(FromProtocolQuad) .Select(q => IntersectQuadWithViewport(q, layoutTask.Result)) .Where(q => ComputeQuadArea(q.ToArray()) > 1); if (!quads.Any()) { throw new PuppeteerException("Node is either not visible or not an HTMLElement"); } // Return the middle point of the first quad. var quad = quads.First(); var x = 0m; var y = 0m; foreach (var point in quad) { x += point.X; y += point.Y; } return( x : x / 4, y : y / 4 ); }
private async Task <(decimal x, decimal y)> ClickablePointAsync() { GetContentQuadsResponse result = null; try { result = await Client.SendAsync <GetContentQuadsResponse>("DOM.getContentQuads", new Dictionary <string, object> { { MessageKeys.ObjectId, RemoteObject[MessageKeys.ObjectId] } }); } catch (Exception ex) { _logger.LogError(ex.Message); } if (result == null || result.Quads.Length == 0) { throw new PuppeteerException("Node is either not visible or not an HTMLElement"); } // Filter out quads that have too small area to click into. var quads = result.Quads.Select(FromProtocolQuad).Where(q => ComputeQuadArea(q) > 1); if (!quads.Any()) { throw new PuppeteerException("Node is either not visible or not an HTMLElement"); } // Return the middle point of the first quad. var quad = quads.First(); var x = 0m; var y = 0m; foreach (var point in quad) { x += point.X; y += point.Y; } return( x : x / 4, y : y / 4 ); }