我正在try Select 一个下拉框,该下拉框仅在单击复选框时显示.我使用过XPath,它似乎在一个浏览器上传递,在其他浏览器上超时.正在使用的浏览器有Chrome、Safari和Firefox.它在Chrome和Safari上失败了,但在Firefox上通过了.
以下是我的代码:
import { test, expect } from '@playwright/test';
test ("User can make a donation", async ({page}) => {
await page.goto('https://app.pws.int.cruk.org/support-us/your-donation');
await expect (page).toHaveTitle('Support us | Cancer Research UK')
const amountBtn = page.locator('#amount10')
const donationType = page.locator('#typeRadioGroup0')
const selectMotivation = page.locator('//*[@id="main"]/form/div[3]/div/fieldset/div[1]/label/select')
const destination = page.locator('#destinationRadioGroup1')
await amountBtn.click({ force: true });
await donationType.click({ force: true });
await selectMotivation.selectOption('In memory of someone');
await destination.click({ force: true });
const selectCancer = page.locator('//*[@id="main"]/form/div[4]/div/fieldset/div[2]/select')
await selectCancer.selectOption('Bowel cancer')
const submit = page.locator('//*[@id="main"]/form/div[5]/div/div/button')
await submit.click({ force: true });
})
我try 在选中复选框后将XPath移动到,但在多个浏览器上仍然失败.日志(log)如下:
1) [webkit] › donation.spec.ts:4:5 › User can make a donation ────────────────────────────────────
Test timeout of 30000ms exceeded.
Error: locator.selectOption: Page closed
=========================== logs ===========================
waiting for locator('xpath=//*[@id="main"]/form/div[4]/div/fieldset/div[2]/select')
============================================================
20 |
21 | const selectCancer = page.locator('//*[@id="main"]/form/div[4]/div/fieldset/div[2]/select')
> 22 | await selectCancer.selectOption('Bowel cancer')
| ^
23 |
24 | const submit = page.locator('//*[@id="main"]/form/div[5]/div/div/button')
25 | await submit.click({ force: true });
2) [chromium] › donation.spec.ts:4:5 › User can make a donation ──────────────────────────────────
Test timeout of 30000ms exceeded.
Error: locator.selectOption: Page closed
=========================== logs ===========================
waiting for locator('xpath=//*[@id="main"]/form/div[4]/div/fieldset/div[2]/select')
============================================================
20 |
21 | const selectCancer = page.locator('//*[@id="main"]/form/div[4]/div/fieldset/div[2]/select')
> 22 | await selectCancer.selectOption('Bowel cancer')
| ^
23 |
24 | const submit = page.locator('//*[@id="main"]/form/div[5]/div/div/button')
25 | await submit.click({ force: true });
有人能帮帮我吗?