python - 使用 Playwright for Python,如何读取输入框的内容
问题描述
在我正在自动化的网站中,我有一个禁用的输入框。
在网站上,它显示一个数字,例如“1”,并具有其他元素来更改值。
<input data-v-a6368fd8="" id="base-amount-input-211" max="10" name="Counter" disabled="disabled" type="number" class="amount-input__number amount-input__number--active">
当我查询元素时
handle = page.querySelector('//input[starts-with(@name, "Counter")]')
我得到了句柄的结果。
当我尝试读取句柄内容时
handle.innerText()
handle.innerHTML()
都是空的 ('')
如何访问当前输入值?
解决方案
另一种方法是简单地使用 的getAttribute()
方法elementHandle
来检索值:
handle = page.querySelector('//input[starts-with(@name, "Counter")]')
value = handle.getAttribute("value")
推荐阅读
- node.js - NodeJS:检测用户是否对文件具有读取权限
- javascript - $.each 函数替换为 for 循环
- c# - EF5 IQueryable 不包含 ToListAsync 的定义
- react-router - react-router 内联渲染道具(Auth0 回调)
- php - MySQL 不执行更新
- css - 将 div 对齐到底部:我是否错误地使用了“align-content-end”?
- bash - 从 AWK 构建 bash 数组
- mysql - MySQL查询以计算按日期范围分组的行
- mongodb - 基于列对文档进行分组,然后从每个组中选择一个文档,该文档是另一列的最大值
- java - 仅从联系人列表的 Firebase 中检索数据