Reputation: 25
I'm using the Selenium WebDriver (Java API)
to test an electron/chromium
based application. The login page of this application has a web-view
(<webview>...</webview>
) which loads a secondary web page in it. I've attached a screenshot of a similar login page and its DOM below for your reference. As you can see in the screenshot, the web-view
loads the secondary web page https://www.google.ca/ in this example. I'll need to interact with the web elements in this secondary web page. Let's say I'm trying to find the Google Search
button and click it in this example as shown below.
WebElement googleSearchButton = driver.findElement(By.xpath("//input[@value='Google Search']"));
googleSearchButton.click();
Unfortunately, I can NOT seem to find any web element in the secondary web page via driver.findElement(By)
. For example, the first line of the above mentioned code snippet throws a NoSuchElementException
.
Does anyone know how to find web elements in a web-view
via the Selenium WebDriver (Java API)
?
Thanks in advance!
Upvotes: 1
Views: 1859
Reputation: 414
https://github.com/electron/electron/issues/2285
Open DevTools in console-tab execute document.querySelector('webview').openDevTools();
it will open you new window with desired HTML.
Or in case using jQuery $('webview').openDevTools();
Maybe just change 'webview'
to your locator, cause I have only one webview on the page.
Cheers.
Upvotes: 0
Reputation: 51
By going through WebView documentation, I see that it is not recommended to use webview in the first place.
Now, coming to your question. You can go through this documentation and make use of JavascriptExecutor to interact with webview using webview's api.
Upvotes: 1