- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从两个 aria-label 值之一获取一个 dom 元素数组。我正在尝试使用 locator.evaluateAll method 来做到这一点.
目前,这是我所能得到的;我试图获取我的 DOM 中的所有按钮,并从那些具有特定 aria-label 属性的按钮中创建一个数组:
const elements = this.page.locator('button');
const allSigButtons = await elements.evaluateAll(
(button) =>
`${button}[aria-label='Sign']` || `${button}[aria-label='Initial']`
);
当我将 allSigButtons 数组打印到控制台时,我得到:
[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement][aria-label='Sign']
显然我做错了什么!
最佳答案
我认为您正在寻找 comma-delimited CSS selectors (logical OR) :
const playwright = require("playwright");
const html = `
<body>
<button aria-label="Sign">foo</button>
<button aria-label="Signy">NO</button>
<button aria-label="Initial">bar</button>
<button aria-label="Initial">baz</button>
<button aria-label="Initia">NOT ME</button>
</body>
`;
let browser;
(async () => {
browser = await playwright.chromium.launch({headless: true});
const page = await browser.newPage();
await page.setContent(html);
const sel = "button[aria-label='Sign'], button[aria-label='Initial']";
const btns = await page.locator(sel);
console.log(await btns.allTextContents()); // => [ 'foo', 'bar', 'baz' ]
})()
.catch(err => console.error(err))
.finally(() => browser?.close())
;
关于javascript - 如何使用 locator.evaluateAll() 在 Playwright 中获取基于 aria-label 的元素(按钮)数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73086318/
使用 Java,我正在尝试等待对我正在等待的 Javascript 脚本之一的响应。 我已经发现我可以使用 waitForResponse ,但是如果在我到达 waitForResponse 语句之前
是否可以定义禁用 Javascript 的浏览器来模拟爬虫查看页面的方式?应该有一个可以通过的选项。 最佳答案 您可以通过javaScriptEnabled在 BrowserContext 选项中:
我想测试标题是否包含特定文本。有这方面的命令吗? await page.goto(‘'); expect(await page.$("data-testid=headline")).toBe("my
我想使用 playwright-python 自动填写一些表格。然后在提交前仔细检查填写内容。但它总是在代码运行结束时关闭浏览器。即使我使用了 handleSIGHUP=False、handleSIG
我目前正在使用 global-setup.ts 文件通过 playwright 加载 url。 await page.goto('https://test1.com/'); 我也在这里面做了额外的代码
在 Web 应用程序(在 React 中实现)中,当我按下特定按钮时,会打开一个新的浏览器选项卡。我想检查是否发生了这种情况以及新标签页的 URL 是否正确。 最佳答案 你可以这样实现它 // @ts
如何使用代理方式打开网页 在 playwright.chromium.launch() 中传入 proxy 参数即可,示例代码如下: 1、同步写法:
playwright也是可以做接口测试的,但个人觉得还是没有requests库强大,但和selenium相比的话,略胜一筹,毕竟支持API登录,也就是说可以不用交互直接调用接口操作了。 怎么用 既
写在前面 还是有些絮叨的感觉,官方翻译和某些博主写那个玩楞,基本都是软件直接翻译后的产物。 读起来生硬不说,甚至有的时候不到是什么意思,真的是实在不敢恭维。 到底是什么意思? 就是你已经登陆过
一、前言 看到这个文章,有的同学会说: 六哥,你为啥不早早就写完python系列的文章。 因为有徒弟需要吧,如果你也想学自学,那这篇文章,可以说是我们结缘一起学习的开始吧! 如果对你有用,建议
一、如何使用代理方式打开网页 在 playwright.chromium.launch() 中传入 proxy 参数即可,示例代码如下: 1、同步写法: from playwright.sync
如何使用代理方式打开网页 在 playwright.chromium.launch() 中传入 proxy&nbs
一、命令行使用详解 使用Pytest插件在Playwright 中来编写端到端的测试。 1、命令行执行测试 pytest --browser webkit --headed 2、使用 pyte
一、常见元素定位 定位器是 Playwright 自动等待和重试能力的核心部分。简而言之,定位器代表了一种随时在页面上查找元素的方法,以下是常用的内置定位器。 1、按角色定位 按显式和隐式可访问
引用剧作家提供的文档,似乎钩子(Hook)(例如:afterAll/beforeAll)只能在规范/测试文件中使用,如下所示: // example.spec.ts import { test, ex
我是开发新手,我在创建一个 e2e 测试时遇到了一个真正的问题。 基本上,我有一个包含 2 行或更多行的表,每行有 5 列(标题、x、y、z 按钮)。 如何使用标题单击正确行上的按钮? (这是一个测试
目录 自动等待及元素执行方法 鼠标双击 获取元素焦点 鼠标悬停 鼠标点击 设置复选框取消或选中
我有这段代码可以使用 python playwright 来定位链接: nfo_link = page.locator('the xpath').get_attribute('href') nfo_l
// foo.ts import { test as base } from "@playwright/test"; const test = base.extend({ foo: "hell
我正在 Playwright 中编写一套测试。这些测试将针对多种环境运行,包括生产环境。但是,生产具有分析功能,我担心定期运行该套件可能会扭曲数字。 有没有什么方法可以识别 Playwright 测试
我是一名优秀的程序员,十分优秀!