I have a working solution, I don't know if google will update to mitigate this. Now this is in c#, but the selenium functionality is basically the same.
Show all the menu items, except the download as menu and return the download as webelement. Use selenium to click it, then select a format and return the webelement to click as well. I couldn't do a click using just javascript, I was unable to figure out how to they triggered it, but clicking it using selenium driver worked just fine.
Make most of the menu's visible and return download as webelement.
document.querySelector(`#docs-file-menu`).className = 'menu-button goog-control goog-
inline-block goog-control-open docs-menu-button-open-below';
document.querySelector(`#docs-file-menu`).setAttribute('aria-expanded', 'true');
document.querySelectorAll(`.goog-menu:not(.goog-menu-noaccel)`)[0].className = 'goog-menu goog-menu-vertical docs-material docs-menu-hide-mnemonics docs-menu-attached-button-above';
document.querySelectorAll(`.goog-menu:not(.goog-menu-noaccel)`)[0].setAttribute('style', 'user-select: none; visibility: visible; left: 64px; top: 64px;');
// download as
// 2 parents above
document.querySelector(`[aria-label='Download as d']`).parentElement.parentElement.className = 'goog-menuitem apps-menuitem goog-submenu goog-submenu-open goog-menuitem-highlight'
return document.querySelector(`[aria-label='Download as d']`).parentElement.parentElement;
Click download as btn:
IWebElement btn = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript(btnClickJs);
btn.Click();
Select format:
var formatCss = document.querySelectorAll(`.goog-menu.goog-menu-noaccel`)[6].querySelectorAll(`.goog-menuitem.apps-menuitem`)
var format = 'injectformathere' ? 'injectformathere' : '.html'
for (let i = 0; i < formatCss.length; i++) {
if(formatCss[i].innerText.indexOf(format)!= -1)
return formatCss[i]
}
return null
Click format:
btn = (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript(btnClickJs);
if (btn != null)
btn.Click();