简体   繁体   中英

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

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

#mas-apps-store-search-paginator kat-icon[name='chevron-right']

I'm kinda assuming that won't work due to the 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:

kat-图标

the <kat-icon> element is within a #shadow-root (open)


Solution

To identify and click on the <kat-icon> element you can use the following locator strategies :

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"]')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM