使用无头浏览器进行调试 [英] Debugging with headless browser

查看:865
本文介绍了使用无头浏览器进行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WebDriver testsuite,当我在普通和无头浏览器中执行它时,它运行不同。当我在无头模式下执行它时,找不到一个元素,但是当我在正常模式下使用相同的代码,相同的驱动程序时,会发现该元素。
我使用此标志设置无头模式:

I have a WebDriver testsuite, which operates different when I execute it in normal and headless browser. There is an element which is not found when I execute it in headless mode, but found when I use the same code, same driver in normal mode. I use this flag to set headless mode:

chromeOptions.addArguments("--headless");

ChromeDriver 2.31 WebDriver 3.5.2 正在使用中。我该怎么调试呢?

There is ChromeDriver 2.31 and WebDriver 3.5.2 in use. How could I debug this?

推荐答案

有两种调试方法。您可以获取页面源并检查有什么不同。

There are two ways to debug. You can get Page Source and check what is different.

现在,当您使用Selenium启动浏览器时,它正在使用调试会话来自动化Chrome。所以你不能用你的网站做远程调试。

Now when you launch a browser using Selenium, it is using the Debugging session to automate chrome. So you can't do a remote debugger to your website using this.

你需要手动启动chrome。

You need to launch chrome manually.

chrome --headless --remote-debugging-port=9222 --disable-gpu http://tarunlalwani.com

现在打开另一个chrome并通过转到 http://127.0.0.1:9222 调试网站,检查现场。

Now in open another chrome and debug the site by going to http://127.0.0.1:9222 and inspect the site.

这篇关于使用无头浏览器进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆