[英]Watir: select an element with multiple custom attributes
When creating a Watir script that clicks a right pagination arrow, I can't seem to find a solution to grabbing the bottom 'kat-icon' tag: https://imgur.com/CNs7kXH创建单击右分页箭头的 Watir 脚本时,我似乎找不到抓住底部“kat-icon”标签的解决方案: https://imgur.com/CNs7kXH
Tried using a lot of different versions of the line below but nothing seems to work.尝试使用以下行的许多不同版本,但似乎没有任何效果。
browser.element(id: 'mas-apps-store-search-paginator').span(name: 'chevron-right').exists?
How should I approach this?我应该如何处理这个?
I would first try a simple CSS selector like我会先尝试一个简单的 CSS 选择器,例如
#mas-apps-store-search-paginator kat-icon[name='chevron-right']
I'm kinda assuming that won't work due to the shadow-root
.我有点假设由于
shadow-root
它将不起作用。 In that case, you'd need to do something like在这种情况下,你需要做类似的事情
shadow_host = driver.find_element(id: 'mas-apps-store-search-paginator')
shadow_root = shadow_host.shadow_root
icon = shadow_root.find_element(name: 'chevron-right')
Given the HTML:鉴于 HTML:
the <kat-icon>
element is within a #shadow-root (open) <kat-icon>
元素在#shadow-root 中(打开)
To identify and click on the <kat-icon>
element you can use the following locator strategies :要识别并单击
<kat-icon>
元素,您可以使用以下定位器策略:
shadow_host = driver.find_element(css: 'kat-pagination.mas-paginator')
shadow_root = shadow_host.shadow_root
right_pagination_arrow = shadow_root.find_element(css: 'kat-icon.nav__icon[name="chevron-right"]')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.