如何获取 Shadow-root 中元素的 cssSelector 路径

问题描述 投票:0回答:1

你能帮我找到元素的正确路径吗

掀背车

这是我用的java代码,显然cssSelector路径是错误的

    WebElement shadowHost2 = driver.findElement(By.xpath("//vmos-flyout"));
    SearchContext shadowRoot2 = shadowHost2.getShadowRoot();
    WebElement shadowContent2 = shadowRoot2.findElement(By.cssSelector("app-vue/div/ul/li[3]/ul/li[4]/div/p"));
java selenium-webdriver css-selectors
1个回答
0
投票

试试这个:

WebElement element = (WebElement) ((JavascriptExecutor)driver)
                .executeScript("return arguments[0].shadowRoot", driver.findElement(By.xpath("//vmos-flyout[@slot='seamless-vmos-flyout']")));
                
element.findElement(By.xpath("//p[text()='Hatchbacks']")).click();
© www.soinside.com 2019 - 2024. All rights reserved.