puppeteer - How to select a drop down menu option in Puppeteer bot?
问题描述
I am trying to customise a Puppeteer bot which fills out a reservation form, searches for an available date and if it’s not available it refreshes the page. The bot only selects some options but I’d like to add more. Currently it leaves the default “1” room in the drop down menu but I’d like to select “2”. Below is the current code and I’d like to select 2 for no_of_rooms
async function prepareAndCheckPage(){
//select 2 rooms
await page.select('#form_no_of_rooms', '2'); //this code doesn't work
//accessibility requirement – this code correctly selects the second radio button
await page.waitForSelector('#form_rooms_0_accessibilityRequirement_1');
const accessibilityRequirement = false;
page.$eval('#form_rooms_0_accessibilityRequirement_' + (accessibilityRequirement ? 0 : 1), elem => {
elem.checked = true;
});
Here is the HTML from the page
<div id="accommodation-add-rooms">
<div class="row / mb-6">
<div class="col-md-7">
<div class="form-group mb-0"><label class="required" for="form_no_of_rooms">Preferred number of rooms*</label><div id="form_no_of_rooms_help" class="d-block / mb-1">Please note your preferred number of rooms and room configuration are not guaranteed.</div><select id="form_no_of_rooms" name="form[no_of_rooms]" class="col-12 col-md-2 form-control" aria-describedby="form_no_of_rooms_help"><option value="1">
1
</option><option value="2">
2
</option></select>
Obviously I'm very inexperienced in this. What am I doing wrong? I’ve tried both form_no_of_rooms and no_of_rooms
解决方案
推荐阅读
- excel - 有没有办法恢复所有 Execl 工作表的先前列的宽度大小?
- python - 只想从字典的值中删除单引号
- error-handling - 网络选项卡Magento 2中的严格来源错误
- wpf - 我想访问目前在非公共成员中的 Prism 导航日志回栈
- google-apps-script - 无法运行 Google Apps 脚本,错误 401:disabled_client
- google-chrome - Primefaces 嵌入式 PDF 媒体仅在 Chrome 中显示为“dynamiccontent.properties.jsf”
- java - 在 java 中使用 iCal4J 库在 ics 文件中添加刷新间隔参数
- laravel - 接收货币价格并计算价格
- android - Android 设备的 PWA 中关于 allowbackup 标签的漏洞
- asp.net-core - 将 asp.net 核心部署到 IIS 后,有关 web.config 身份验证部分的错误 500 配置错误