Q: Selenium with Java - unable to grab h5 element I am working with the following page source and must extract the size of the given item of clothing: view-source:https://www.aboutyou.de/p/hugo/buegelleichtes-hemd-elvor-3636873
There is an h5 element with the line "PRODUKTMAße (Größe: M)".
Here is what the code with surrounding containers looks like:
<div class="js-adp-tab js-adp-tab-description info-tab adp-description">
    <div class="description-text bottom-0" itemprop="description">
        <div>
            <strong>Bügelleichtes Hemd 'Elvor'</strong> &nbsp;<small class="gray-light">Artikel-Nr: <span>HGO0017001000001</span></small>
        </div>
        <p class="bottom-0">
            In Extra-Slim-Fit designt bietet das HUGO Hemd Elvor eine moderne, maskuline Silhouette und einen angesagten Look. Ergänzt wird der cleane Style durch den schmalen Stehkragen, die geraden Manschetten und dezent schimmernde Logo-Knöpfe. Dieses Hemd verleiht eine edle Attitüde ohne aufzutragen!
        </p>
        <h5>PRODUKTMAßE  (Größe: M)</h5>
        <p>
            Gesamtlänge: 76 cm<br>
            Ärmellänge: 68 cm<br>
        </p>
    </div>
</div>

How can I get the text of this one h5 element? I have tried several combinations, the most recent one of which has been:
String size = driver.findElement(By.cssSelector("h5:contains('PRODUKTMAßE')")).getText(); 


A: Simplest approach is probably to use XPath:
String size = driver.findElement(By.xpath("//h5[contains(text(), 'PRODUKTMAßE')]")) 

Be sure you have only one h5 in your page otherwise you'll have to iterate over driver.findElements and filter a little more ...

A: You may use xpath like below:
driver.findElement(By.xpath("//p[contains(.,'In Extra-Slim-Fit design')]/../h5")).getText();

It should work.

A: Don't use special symbols in locator like 'ß'. 
Build css/xPath from top to bottom logically, not including parts like "p/../h5" - it's not ok because that locator tells you nothing + it can be easily changed by developer, and you will have to rewrite your locator
Try cssSelector(".info-tab .description-text h5") 
i'm not sure what info popup you are looking for, possibly you should even adjust it to:
cssSelector(".info-tab.adp-description .description-text h5") 

A: I have checked the webpage. I am not sure what you have missed but the below code works for me.
public static void main(String[] args) 
{

System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\Selenium\\Web Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
driver.get("https://www.aboutyou.de/p/hugo/buegelleichtes-hemd-elvor-3636873");
//Scrolling down
((JavascriptExecutor)driver).executeScript("scroll(0,400)");

//Click the tab "produktdetails" in which PRODUKMABE exists
driver.findElement(By.xpath("//div[@class='btn-tab V3adp__productDescriptionTab V3adp__productDescriptionTab--1outOf4'][2]")).click();
String size = driver.findElement(By.xpath("//div[@class='description-text bottom-0']/h5")).getText();
System.out.println(size);

}

Hope this helps you. Thanks.
