Using selenium to automate a chrome://inspect instance doesn't update body

253 views
Skip to first unread message

Johan van Poppel

unread,
Apr 16, 2020, 12:39:14 PM4/16/20
to Selenium Users

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.

Does anyone have experience with using Selenium WebDriver to automate the usage of chrome remote devices using chrome://inspect, and especially the part to get the correct page source in focus in order to be able to find and use elements on the page? 

Serguei Kouzmine

unread,
Apr 17, 2020, 9:04:24 PM4/17/20
to Selenium Users
probably shawow DOM. There are already projects to find elements under 
is it not very easy but doable

Johan van Poppel

unread,
Apr 20, 2020, 8:03:39 AM4/20/20
to Selenium Users
Hi Serguei, thanks for you answer.

However, there don't seem to be any shadow root elements present in the DOM.
The page source my webdriver returns with driver.getPageSource(); seems to contain a lot of CSS, but not that much more.
https://pastebin.com/xniM2tsV (getPageSource() value)

This is the DOM of the remote devices window (as you can see by the buttons, the screencastview and the elementspanel), but not the "inner" DOM of the remote device. I try to fetch the DOM of the device in the screencastview.



Op zaterdag 18 april 2020 03:04:24 UTC+2 schreef Serguei Kouzmine:

Serguei Kouzmine

unread,
Apr 20, 2020, 1:22:27 PM4/20/20
to Selenium Users
@Johan van Poppel page source may not show shadow DOM
compare e.g.
chrome://downloads/

Capture_shadow_root.JPG

ahmed merzoug

unread,
Dec 8, 2022, 8:11:39 PM12/8/22
to Selenium Users
Hello @johan, 

I'm having the same problem, did you find a solution please? 

Regards,
Reply all
Reply to author
Forward
0 new messages