0

我正在尝试使用“ClickAsync”选择一个下拉元素,因为用户模拟点击以使用 xPath 在下拉列表中选择一个项目。但不幸的是,我无法执行此操作。虽然我可以使用单击展开下拉列表,但无法选择可用选项。

        await page.GotoAsync("https://letcode.in/dropdowns");
        await page.WaitForTimeoutAsync(3000);
        //await page.ClickAsync("xpath=//select[@id='fruits']/option[3]");
        
        await page.ClickAsync("xpath=//select[@id='fruits']");// this will expand the dropdown
        //await page.ClickAsync("xpath=//option[3]");
        await page.WaitForTimeoutAsync(3000);
4

1 回答 1

1

您应该改用该SelectOptionAsync方法。

await page.SelectOptionAsync(
    "xpath=//select[@id='fruits']", 
    new SelectOptionValue { Index = 2 }));
于 2021-10-06T15:55:46.280 回答