gpt4 book ai didi

Java Selenium : Switch to iframe inside shadow-root open inside webview

转载 作者:行者123 更新时间:2023-12-03 17:32:13 40 4
gpt4 key购买 nike

我正在尝试使用 Java Selenium 在我的节点 webkit 应用程序上自动化一些测试。它的工作方式是 chromedriver 附加到主窗口,但我访问的任何站点都作为 webview 在 DOM 中,如下所示:

带有 DOM 的图片:

enter image description here

我将如何处理这个问题?在 java 中扩展 shadow root 元素并尝试将上下文切换到它下面的 iframe 之后,我只是得到与我正在调用的函数无关的随机错误(在我看来)。例如:

WebElement shadowRoot = expandShadowElement(root);

WebElement iframe = shadowRoot.findElement(By.cssSelector("iframe"));
Driver.getWebDriver().switchTo().frame(iframe);

WebElement city = Driver.getWebDriver().findElement(By.className("input-btn-group"));

第二行给了我一个“isShown 的参数必须是元素类型”,但这没有意义,因为我没有调用 isShown 函数。

最佳答案

根据您的问题,一旦您扩展影子根元素,就会为所需的 <iframe> 引入 WebDriverWait是 frameToBeAvailableAndSwitchToIt 如下:

WebElement shadow_root = Driver.getWebDriver().findElement(By.xpath("//webview[@class='sel' and contains(@src,'https://www.google.com/?')][starts-with(@id,'w_Webo')]"));
WebElement shadow_root_element = (WebElement)((JavascriptExecutor)driver).executeScript("return arguments[0].shadowRoot", shadow_root);
new WebDriverWait(Driver.getWebDriver(), 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe")));

备注 :根据屏幕截图,您已共享标识为 By.className("input-btn-group") 的元素不可见,也不包含在答案中。

关于Java Selenium : Switch to iframe inside shadow-root open inside webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51629411/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com