The website is https://www.nseindia.com/get-quotes/derivatives?symbol=AARTIIND
Here is my code:
driver.get("https://www.nseindia.com/get-quotes/derivatives?symbol=AARTIIND");
try {
wait.until(ExpectedConditions.elementToBeClickable(By.id("optionChain")));
} catch (Exception e) {
}
driver.findElement(By.id("optionChain")).click();
try {
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.xpath("/html/body/div[10]/div[1]/div/section/div/div/div/div/div[1]/div[2]/div/div/div/div[2]/div[2]/div[2]/div/table[1]/tbody/tr"), 10));
} catch (Exception e) {
}
Thread.sleep(10000);
List<WebElement> table = driver.findElements(By.xpath("/html/body/div[10]/div[1]/div/section/div/div/div/div/div[1]/div[2]/div/div/div/div[2]/div[2]/div[2]/div/table[1]/tbody/tr"));
int optionChainSize = table.size();
I want to remove the Thread.sleep() command, but it invariably ends up with optionChainSize = 0.
I use "wait.until(ExpectedConditions..." to wait for the "Option Chain" element to load, and click it. Thereafter a table appears, but try as I might, I cannot get the program to wait for it to load, except a crude Thread.sleep command.
I have tried the bottom row that says "tot", the top right where it says "Underlying:", but they all just appear to load before the table. I have tried "numberOfElementsToBeMoreThan" and put the locator for the "tr" xpath, as follows:
try {
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.xpath("/html/body/div[10]/div[1]/div/section/div/div/div/div/div[1]/div[2]/div/div/div/div[2]/div[2]/div[2]/div/table[1]/tbody/tr"), 10));
} catch (Exception e) {
Is there any way to do this right? I don't understand the "staleness" property, could that be of use?