due to some scenarios, I need to access chrome://downloads/ by headless mode but I got the error that looks like this:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#useragent"}
(Session info: headless chrome=91.0.4472.124)
After trying to search around and try much time, but failed I've added a lot of options for chrome as below:
ChromeOptions options = new ChromeOptions()
options.addArguments('--headless', '--start-maximized', '--window-size=1366,768', 'disable-blink-features=AutomationControlled',
'privileged', '--test-type', '--disable-gpu', '--no-first-run', '--no-default-browser-check', '--ignore-certificate-errors',
'--disable-extensions', '--proxy-bypass-list=*', '--disable-dev-shm-usage', '--no-sandbox', '--lang=en_US', '--allow-running-insecure-content')
options.addArguments('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36')
options.setExperimentalOption('useAutomationExtension', false)
options.setExperimentalOption('excludeSwitches', ['enable-automation'])
options.addArguments('--proxy-server=\'direct://\'')
System.setProperty('webdriver.chrome.driver', ((RunConfiguration.getProjectDir() + '\\Data Files\\builds\\chromedriver_') +
GlobalVariable.chromeDriverVersion) + '.exe')
WebDriver driver = new ChromeDriver(options)
driver.navigate().to('chrome://version/')
WebElement userAgent = driver.findElement(By.cssSelector('#useragent'))
String txtUserAgent = userAgent.getText()
println(txtUserAgent)
But no luck happened
So anyone could help to resolve this problem, thanks a lot! PS: It can work fine on normal mode.