0

I am trying to access the table elements under Shadow root but I am unable to access it.

The structure is as shown below Structure of the shadow DOM

I have tried below code but still having failure

${title}=    Get Row Count Under Shadow Root Element
log    ${title}
Close Browser
import selenium
from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn

def expand_shadow_element(driver, element):
  shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
  return shadow_root

def get_row_count_under_shadow_root_element():
  seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
  driver = seleniumlib.driver

  root1 = driver.find_element_by_tag_name('vaadin-grid')
  shadow_root1 = expand_shadow_element(driver, root1)
  row_count = shadow_root1.find_element_by_xpath("//div[@id='scroller']//table[@id='table']").get_attribute("aria-rowcount")
  # row_count = driver.find_element_by_xpath("//div[@id='scroller']").click()

  return  row_count  

Can someone guide me what is wrong in this.

Also a working code would be really appreciated.

  • I think your question is somewhat duplicate to this question: https://stackoverflow.com/questions/55761810/how-to-automate-shadow-dom-elements-using-selenium – Tatu Lund May 12 '21 at 05:40
  • As you are using Vaadin you could be interested in https://vaadin.com/testbench which also extends Selenium with helpers to test Vaadin's web components such as Grid. – Tatu Lund May 12 '21 at 05:41
  • Does this answer your question? [How to automate shadow DOM elements using selenium?](https://stackoverflow.com/questions/55761810/how-to-automate-shadow-dom-elements-using-selenium) – Danny '365CSI' Engelman May 12 '21 at 07:33
  • I voted to close, see duplicate. StackOverflow doesn't get better when everyone asks the same question. Please search before you ask a question. – Danny '365CSI' Engelman May 12 '21 at 07:35

0 Answers0