我有一个小问题,无法找到使用 Microsoft Playwright 框架的答案。根据文档,您可以使用以下代码获取 iframe:
const frame = page.frame('frame-login');
Run Code Online (Sandbox Code Playgroud)
但是如何使用选择器来查找 iframe 并与之交互?我需要使用 CSS 选择器来查找我的 iframe,因为它没有 id。
任何帮助表示赞赏
我正在使用 playwright.js 为https://target.com编写脚本,并且在您提交运输信息的页面上,如果您之前已完成结帐流程,它将提供使用已保存地址的选项目标帐户。
我想每次运行脚本时都输入新的运输信息,所以我必须让编剧在页面上点击删除,然后输入运输信息。
下面显示的函数用于单击删除,但随后超时if (await page.$$("text='Delete'") != [])而不是执行else该函数的一部分。
我怎样才能重写这个函数,让它简单地检查元素(选择器:)是否text='Delete'存在,如果存在则单击它,如果不存在则执行函数的填充部分?
async function deliveryAddress() {
if (await page.$$("text='Delete'") != []) {
await page.click("text='Delete'", {force:true})
await deliveryAddress()
} else {
await page.focus('input#full_name')
await page.type('input#full_name', fullName, {delay: delayms});
await page.focus('input#address_line1')
await page.type('input#address_line1', address, {delay: delayms});
await page.focus('input#zip_code')
await page.type('input#zip_code', zipCode, {delay: delayms});
await page.focus('input#mobile')
await page.type('input#mobile', phoneNumber, {delay: delayms});
await page.click("text='Save & continue'", {force:true})
}
}
Run Code Online (Sandbox Code Playgroud) 我想测试一个元素是否已被渲染。所以我希望期望 if 存在。有这个命令吗?
\nawait page.goto(\xe2\x80\x98<http://localhost:3000/>');\nconst logo = await page.$(\xe2\x80\x98.logo\xe2\x80\x99)\n\n// expect(logo.toBeInDocument())\nRun Code Online (Sandbox Code Playgroud)\n