python - 如何通过 selenium-webdriver 和 Python 根据 html 在没有唯一标识符的文本框中单击
问题描述
<div class="panel">
<div data-bind="foreach: UriParameters">
<div>
<input readonly="true" spellcheck="false" tabindex="100" class="uriParameterLabel" data-bind="value: '{' + name + '}'">
<span>= </span>
<input spellcheck="false" data-bind="value: value, valueUpdate: 'afterkeydown', enable: enabled">
<input type="checkbox" data-bind="checked: enabled">
</div>
<div>
<input readonly="true" spellcheck="false" tabindex="100" class="uriParameterLabel" data-bind="value: '{' + name + '}'">
<span>= </span>
<input spellcheck="false" data-bind="value: value, valueUpdate: 'afterkeydown', enable: enabled">
<input type="checkbox" data-bind="checked: enabled">
</div>
</div>
</div>
我正在学习自动化 API 测试并遇到一个没有唯一标识符的元素,因为它会自动从端点获取其值。
解决方案
根据您共享的HTML ,以找到与您需要诱导WebDriverWait元素可点击的字段对应的文本框,您可以使用以下解决方案:{userid}
XPATH
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='panel']/div[contains(@data-bind, 'UriParameters')]/div//following::input[2]"))).click() #or WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='panel']/div[contains(@data-bind, 'UriParameters')]/div//following::input[2]"))).send_keys("Ice")
推荐阅读
- string - postgres中字符串的部分匹配和完全匹配
- c# - MongoDB C# CRUD
- sql-server - 裁剪 SQL Server Management Studio 窗口
- c# - C#输出自己的List数据类型
- instagram - 禁用旧 API 后,如何将我的 Instagram 提要添加到我的个人网站?
- python - kivy 滚动视图卡住了
- python-3.x - 消息:“geckodriver”可执行文件需要在 PATH 中
- xpages - 在 XSP 属性中使用运行时优化的 JS 和 CSS 资源会导致错误
- python - 预测变量的线性权重过去的回归值
- python - Django ... url 路径中的错误?