是否可以使用 python-selenium在 Shadow DOM 中找到元素?
示例用例:
我有这个input有type="date":
<input type="date">
我想单击右侧的日期选择器按钮并从日历中选择一个日期。
如果您检查 Chrome 开发者工具中的元素并展开日期输入的 shadow-root 节点,您会看到按钮显示为:
<div pseudo="-webkit-calendar-picker-indicator" id="picker"></div>
屏幕截图展示了它在 Chrome 中的外观:

通过 id 查找“选择器”按钮结果为NoSuchElementException:
>>> date_input = driver.find_element_by_name('bday')
>>> date_input.find_element_by_id('picker')
...
selenium.common.exceptions.NoSuchElementException: Message: no such element
我还尝试按照此处的建议使用::shadow和/deep/定位器:
>>> driver.find_element_by_css_selector('input[name=bday]::shadow #picker')
...
selenium.common.exceptions.NoSuchElementException: Message: no such element
>>>
>>> driver.find_element_by_css_selector('input[name=bday] /deep/ #picker')
...
selenium.common.exceptions.NoSuchElementException: Message: no such element
请注意,我可以通过向其发送密钥来更改输入中的日期:
driver.find_element_by_name('bday').send_keys('01/11/2014')
但是,我想通过从日历中选择来专门设置日期。
