如何使用Selenium获取Chrome性能lighthouse数据

huangapple go评论93阅读模式
英文:

How to get Chrome Performance lighthouse data using Selenium

问题

很抱歉,根据您的要求,我只会翻译代码之外的部分。以下是您提供的内容的翻译:

有没有Java API可以使用Selenium Java捕获Chrome性能Lighthouse数据?

英文:

is there any java API to capture Chrome Performance Lighthouse data using selenium Java?

答案1

得分: 1

这可能不是你要的答案,但你可以尝试类似这样的方法;

例如,这个示例计算浏览器中的滚动性能;

public static String toLastElement(WebDriver driver, List<WebElement> webElementList) {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    int y = webElementList.get(webElementList.size() - 1).getLocation().getY();
    return (String) js.executeScript("var start = performance.now(); " +
        "window.scrollTo(0," + y + "); " +
        "var end = performance.now(); " +
        "return '' + (end - start) + '';");
}

总之,你可以在Selenium Webdriver中使用JavaScript来测量性能。

英文:

This is probably not your answer but you can try something like this;

For example this calculates Scroll performance of in browser;

public static String toLastElement(WebDriver driver, List&lt;WebElement&gt; webElementList) {
        JavascriptExecutor js = (JavascriptExecutor) driver;
        int y = webElementList.get(webElementList.size() - 1).getLocation().getY();
        return (String) js.executeScript(&quot;var start = performance.now(); &quot; +
                            &quot;window.scrollTo(0,&quot; + y + &quot;); &quot; +
                            &quot;var end = performance.now(); &quot; +
                            &quot;return &#39;&#39; + (end - start) + &#39;&#39;;&quot;);
    }

In summary you can use javascript to measure performance in Selenium Webdriver.

huangapple
  • 本文由 发表于 2020年5月29日 19:08:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/62084525.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定