通过ID找到多个元素
我试图通过其各自的ID找到多个元素 元素命名
dcm保留限制限制 - 元素输入 - X
,x是元素的数量,可能是:
dcm-reservation-limit-multiple-input-generic-0
dcm-reservation-limit-multiple-input-generic-1
dcm-reservation-limit-multiple-input-generic-2
...
dcm-reservation-limit-multiple-input-generic-10
列表还在继续。 我已经尝试过此代码:
pricesToFind = driver.find_elements_by_xpath(".//*[@id='dcm-reservation-limit-multiple-input-generic-']")
没有任何成功,结果始终返回null,即使它们确实存在
HTML以帮助:
<input _ngcontent-ihk-c34="" autocomplete="off" class="lib-input" maxlength="11" type="text" id="dcm-reservation-limit-multiple-input-variation-0">
输入名称是由JavaScript随机生成的,因此通过输入名称刮擦它是毫无用处的。
I am trying to find multiple elements by their respective ids
The elements are named
dcm-reservation-limit-multiple-input-generic-X
with X being the number of elements, it could be:
dcm-reservation-limit-multiple-input-generic-0
dcm-reservation-limit-multiple-input-generic-1
dcm-reservation-limit-multiple-input-generic-2
...
dcm-reservation-limit-multiple-input-generic-10
and the list goes on.
I've tried already this code:
pricesToFind = driver.find_elements_by_xpath(".//*[@id='dcm-reservation-limit-multiple-input-generic-']")
without any success, the results always return NULL even if they really exist
piece of HTML to help:
<input _ngcontent-ihk-c34="" autocomplete="off" class="lib-input" maxlength="11" type="text" id="dcm-reservation-limit-multiple-input-variation-0">
the input name is randomly generated by javascript, so it's useless to scrape it via input name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用包含或 starter ?
pricestofind = driver.find_elements_by_xpath(“ .///* [contains(@ID,'dcm-rimit-mimit-multiple-multiple-input-generic-generic--')]”)
pricestofind = driver.find_elements_by_xpath(“ .///* [starting-with(@ID,'dcm-kerveration-limit-multiple-multiple-input-generic - ')]”)
Use contains or starts-with?
pricesToFind = driver.find_elements_by_xpath(".//*[contains(@id,'dcm-reservation-limit-multiple-input-generic-')]")
pricesToFind = driver.find_elements_by_xpath(".//*[starts-with(@id,'dcm-reservation-limit-multiple-input-generic-')]")
我个人从来没有经常使用硒,但是我假设地知道该怎么做。我会使用一段时间循环,然后一遍又一遍地运行它。 (只是让您知道,我无法实际测试这一点,因为我在任何具有相同条件的网站中都找不到任何元素)
希望这会有所帮助。我不能保证此代码会起作用,但是现在您对如何实现这一目标有了一个想法。
I personally have never used Selenium a lot, but I hypothetically know how to do this. I would use a while loop, and then run it over and over again. (Just letting you know, I have no way to actually test this, as I couldn't find any elements in any website that have those same conditions)
Hopefully this helps. I make no guarantees that this code will work, but now you have an idea on how to make this happen.