5

I am trying to automate some tests on my node webkit app using Java Selenium. The way it works is that the chromedriver attaches to the main window, but any site that I access is in the DOM as a webview like so:

Picture with the DOM:

enter image description here

How would I approach this? After expanding the shadow root element in java and trying to switch the context to the iframe below it, I just get random errors (in my opinion) that do not pertain to the function I'm calling. For example:

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"));

The second line gives me a "Argument to isShown must be of type Element", but that does not make sense as I am not calling the isShown function.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Alex Selea
  • 51
  • 2
  • 1
    Please have a look at this thread :https://stackoverflow.com/questions/42468715/selenium-webdriver-cant-find-elements-at-chrome-downloads – dangi13 Aug 01 '18 at 09:26
  • 1
    I have seen that thread, the difference is that in that issue, there is only a shadow root and accessing that is no issue, but my shadowroot is inside a webview, and beneath the shadowroot is the iframe that I try to access – Alex Selea Aug 01 '18 at 09:42
  • 1
    Did you finds solution for it? – Tymur Kubai aka SirDiR Jul 31 '20 at 15:22

3 Answers3

0

As per your question, once you expanding the shadow root element induce WebDriverWait for the desired <iframe> to be frameToBeAvailableAndSwitchToIt as follows:

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")));

Note: As per the screenshot you have shared the element identified as By.className("input-btn-group") isn't visible and is not included within the answer.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

We can switch to iframe inside shadow dow by following these 3 steps

step 1: get the shadow root element

step 2: Using that shadow root element find the iframe web element

step 3: Now switch into the iframe which we got in step 2

loc = Locator.new(:xpath,"//locator_used_to_get_shadow_root")
sr = @driver.gets_shadow_root(loc)

iframe_inside_shadowroot = sr.find_elements(:css, "iframe")

driver.switch_to.frame(iframe_inside_shadowroot)
0

Solve similar issue for electron. In electron they have their own wrapper on top of webview, that based on Chromium webview.

But for chrome webdriver solution's may be the same.

https://stackoverflow.com/a/63227482/4577788