Javascript 木偶戏中的斜视测试
如何在Puppeter中测试scrollIntoView()属性? 这就是我所尝试的:Javascript 木偶戏中的斜视测试,javascript,puppeteer,Javascript,Puppeteer,如何在Puppeter中测试scrollIntoView()属性? 这就是我所尝试的: it("should scroll to the right comment", async function() { await page.goto('http://127.0.0.1:3000/page/test#1', { waitUntil: 'domcontentloaded' }); await page.waitForSelector("ul.timeline-c
it("should scroll to the right comment", async function() {
await page.goto('http://127.0.0.1:3000/page/test#1',
{ waitUntil: 'domcontentloaded' });
await page.waitForSelector("ul.timeline-comments", { visible: true });
await page.waitForSelector("li.timeline-comment[name='1']", { visible: true });
const result = await page.evaluate(() => {
document.querySelector("li.timeline-comment[name='1']").scrollIntoView();
});
console.log(result);
}).timeout(0);
----
This is the result from the console.log(result):
---
undefined
✓ should scroll to the right comment (189ms)
下面是我要测试的代码部分:
$("li.timeline-comment[name='" + comment_id + "']")[0].scrollIntoView();
您的问题是如何测试DOM元素是否在视图中?如果是,您必须获取DOM的坐标并检查它是否存在于视图中。好的,谢谢。我将尝试这是您的问题是如何测试DOM元素是否在视图中?如果是,您必须获取DOM的坐标并检查它是否存在于视图中。好的,谢谢。我试试这个