Skip to main content

Hello everyone, I'm getting trouble to find some elements with By.cssSelector(). Every time that I use this code: WebDriver.findElement(By.cssSelector("button[name='0']")), occurs this error: no such element: Unable to locate element: {"method":"css selector","selector":"button[name='0']"} But when I try to find the element with WebDriver.findElement(By.xpath("//button[@name='0']")),It works!

 

OBS: the element is located inside vlocity_ins-omniscript-custom-lwc tag and <slot> tag.

3 risposte
  1. 10 apr 2022, 11:56

    This is because of the polyfill technology used to render lightning web components.

     

    See this article, p.3:

    https://help.salesforce.com/s/articleView?id=000352057&type=1

     

    Convert non-XPath locators to XPath

     

    LWC uses a polyfill to implement shadow DOM rather than a native browser implementation. This implementation restricts Selenium access by non-XPath selectors, like By.cssSelector(), but still allows direct access with By.xpath(). The simplest fix is to convert your non-XPath locators to XPath.

0/9000