Unable to locate element in Selenium using XPath even though the element is visible in Console for the same XPath while inspecting

Solution for Unable to locate element in Selenium using XPath even though the element is visible in Console for the same XPath while inspecting
is Given Below:

I am trying to read and print “Recommended for you” from one of the sections in website https://www.noon.com/uae-en/

When I write xpath for that element which is //h3[@class="sc-dlfnbm eFXxew"] I can see it in my console. But when executed in Java Selenium it returns an exception error stating unable to locate element

“Exception in thread “main” org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:”xpath”,”selector”:”//h3[@class=”sc-dlfnbm eFXxew”]”}”

Below is the actual code written:

    WebDriver driver = new ChromeDriver();
    driver.get("https://www.noon.com/uae-en/");
    driver.manage().window().maximize();
    System.out.println(driver.findElement
   (By.xpath("//h3[@class="sc-dlfnbm eFXxew"]")).getText());
    

You need to use action chains to move to the mentioned web element first then you can get the text, see below :-

Code :

WebDriver  driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.noon.com/uae-en/");
WebDriverWait wait = new WebDriverWait(driver, 30);
Actions action = new Actions(driver);
action.moveToElement(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h3[@class="sc-dlfnbm eFXxew"]")))).perform();
System.out.println(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h3[@class="sc-dlfnbm eFXxew"]"))).getText());

It seems to me that this page has some loading tricks.
I suggest go in parts, first access other parts of the page to check the loading, for example, the logo, the menu, and after your section.

It’s important to know how the system works to do the automation.