You’re mixing up xPath and CSS. Below is the example how you can use CSS for fetching what you need:
List<WebElement> labels = driver.findElements(
new ByChained(By.cssSelector("#residenceChoice"),
By.cssSelector(".hb-label-tekst")
));
labels.forEach(webElement -> {
System.out.println("Label text: " + webElement.getText());
System.out.println("Label 'for': " + webElement.getAttribute("for"));
});
And this is the exampel for xPath:
List<WebElement> labels = driver.findElements(By.xpath("//*[@id='residenceChoice']//label[@class='hb-label-tekst']"));
labels.forEach(webElement -> {
System.out.println("Label text: " + webElement.getText());
System.out.println("Label 'for': " + webElement.getAttribute("for"));
});
CLICK HERE to find out more related problems solutions.