0

I want to automate some tests for a chrome extension, but in order to do that, I have to dynamically get that extension's ID.

To get the extension's ID, I figured that I could navigate to chrome://extensions and click on the "Details" for my extension, and then get the current URL (which contains the extension's ID).

But for some reason, I am not able to interact with mostly anything in that chrome://extensions webpage. I don't even see the page source properly when calling webdriver.page_source in my code.

I tried calling webdriver.find_elements_by_class, by id, by xpath but nothing works, since my extension's name is not even in the page_source generated by selenium (however, if I interact with the browser and inspect the elements, I can see my extension's name there).

chrome.find_element_by_id("detailsButton").click()  # should redirect me to my extension... but selenium can't find that button

I expected selenium to click on the "Details" button, but it cannot find that element.

What happens: https://i.stack.imgur.com/peLSz.png <- I want to find the ID of the first extension, by clicking on it.

cosminp
  • 258
  • 2
  • 4
  • 15
  • It would be better to find some Chrome API instead of "clicking" through the settings page. It may be somehow blocked from automatic tools because of security measures? – h4z3 Nov 07 '19 at 07:57
  • The problem is that the extension has an ID in the original Chrome browser, and another ID in the browser opened by selenium. This was the only way I could think of that might get me the right extension ID. – cosminp Nov 07 '19 at 08:02
  • That page uses ShadowDOM so you would need to recursively descend through the nested Shadow roots to find your element. Anyway, I think you should use a different approach. For example you can [pin the extension id](/a/23877974) to the real id or rewrite the tests so that the id isn't needed or you can get it from your extension as chrome.runtime.id. – wOxxOm Nov 07 '19 at 08:32
  • I will try to recursively descend through the shadow roots, thank you! – cosminp Nov 07 '19 at 09:51

0 Answers0