Hi there!
I am trying to automate testing that requires connecting to an android chrome browser via the Chrome Remote Devices devtool, using Selenium. Right now, the first step is opening the chrome://inspect url using the webdriver, finding and clicking the 'inspect' button for the android device, switching the driver window to the newly opened window (as clicking 'inspect' will open a new window) and refreshing once.
The code I use to change the driver window to the newly opened devtools window:
Set<String> handles = driver.getWindowHandles();
String currentWindowHandle = driver.getWindowHandle();
handles.remove(currentWindowHandle);
ArrayList<String> handlesList = new ArrayList<String>(handles);
driver.switchTo().window(handlesList.get(0));(Please note that there are only two windows active at this time, the chrome://inspect window and the devtools remote device window.)
This all goes fine, the result after these steps is having a WebDriver with a fully initiated remote device devtool window in focus. However, when I try to find an element, nothing can be found. Printing the current URL (using driver.getCurrentURL()) shows it connects to a url in the form of devtools://devtools/remote/serve_rev/@[ ... ]/inspector.html?remoteVersion=69.0.3497.100&remoteFrontend=true&dockSide=undocked, which is correct. However, the page source for this URL is not.
In the remote devices window, as soon as the connection with the remote browser is made, a script renews the entire HTML body, styling, scripting, et cetera. The initial DOM model shows quite a bare empty page with just some scripts present. However, as soon as a connection is made the DOM model changes and shows the page source of the remote browser.
Re-fetching the page HTML using driver.findElement(By.tagName("body")).getAttribute("innerHTML"); still shows the 'old' html, not the updated.