Initially, I posted my question here:
Extracting content from a dynamic web site using a Java Library
Then, after reading and applying the info from the question below:
Selenium Webdriver : not displaying the correct Li elements
I installed a selenium chrome driver (Version ChromeDriver 74.0.3729.6), my chrome browser has version 74.0.3729.169. The selenium WebDriver java object is still unable to correctly find the number of elements on my web-page, altough I simulated a scroll-down and the chrome browser that the driver opened did correctly show the total number of 20 elments.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ImmoweltBot {
public static final String URL2 = "https://www.immowelt.at/liste/wien-2-leopoldstadt/wohnungen/mieten?sort=price&cp=2";
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Temp\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
webDriver.get(URL2);
WebDriverWait wait = new WebDriverWait(webDriver, 15);
By searchResults = By.xpath("//*[contains(@class, 'listitem clear relative js-listitem')]");
JavascriptExecutor js = (JavascriptExecutor)webDriver;
webDriver.manage().window().maximize();
js.executeScript("window.scrollBy(0,1000)");
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(searchResults, 4));
List<WebElement> elemnts = webDriver.findElements(searchResults);
System.out.println(elemnts.size());
}
}
My web-page:
https://www.immowelt.at/liste/wien-2-leopoldstadt/wohnungen/mieten?sort=price&cp=2
Any help will be appreciated. Thank you!