Y
Y
Yuriy_Puhlik2018-10-02 10:21:55
Java
Yuriy_Puhlik, 2018-10-02 10:21:55

Why does --headless Chrome throw NoSuchElementException?

In normal Chrome, the code runs fine, but when I add --headless mode, the program throws NoSuchElementException while searching for an element with Select. With what it can be connected?
Select code:

Select select = new Select(driver.findElement(By.xpath("//select[@class='accProvinces']")));

HTML:
<select class="accProvinces" id="ddlProvinces" name="ddlProvinces">
<option value="240">Athens</option>
.................
</select>

Chrome initialization:
ChromeOptions options = new ChromeOptions();
options.setBinary("pathToChrome.exe");
options.addArguments("--headless", "window-size=1680x1050");
WebDriver driver = new ChromeDriver(options);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2018-12-14
kuzmin @sergueik

interesting
1. what's in e.getMessage() ? probably there he says why he's not the one.
and as always
// Declare a wait time
wait = new WebDriverWait(driver, flexibleWait);
// Selenium Driver version sensitive code: 3.13.0 vs. 3.8.0 and older
wait.pollingEvery(Duration.ofMillis(pollingInterval));
// wait. pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
WebElement element = wait.until(ExpectedConditions.visibilityOf(driver
.findElement(By.xpath("//select[@class='accProvinces']"))));
3. tried to find at least some elements on the page (for example, parents and children) and what's inside?
System.err.println("element check: " + element.getAttribute("innerHTML"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question