Task at hand:
1) Navigate to the following URL:
2) Choose "FO Stocks" from the selection box to display a new table of FO Stocks.
3) Sort the table in descending order by clicking on the "FFM Column" header.
Extract the top 5 rows from the table.
My approach:
Utilizing Selenium Webdriver with Java
1) Successfully accessed the URL in FireFox, attempted loading in Chrome which took longer to load the page entirely.
2) Upon webpage loading, I adjusted the Selection Box Value to "FO" by utilizing the ID of the select box and specifying the value of the option. The code snippet below demonstrates this.
Select dropdown = new Select(driver.findElement(By.id("selId")));
dropdown.selectByValue("fo");
Issue: The table does not update values according to the selected option possibly due to the onchange() function in JavaScript not executing/enabling after changing the value of the selection box on that page.
3) Seeking advice on how to click on this column using Selenium Webdriver (all tips are appreciated).
Code snippet as follows:
public class FirstSeleniumTest {
WebDriver driver;
public void waitForLoad(WebDriver driver) {
System.out.print("waiting for javascript successfully");
new WebDriverWait(driver, 120).until((ExpectedCondition<Boolean>) wd ->
((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
}
public void launchBrowser() {
// System.setProperty("webdriver.chrome.driver", "C:\\Downloads\\chromedriver_win32\\chromedriver.exe");
// driver = new ChromeDriver();
System.setProperty("webdriver.gecko.driver","C:\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");
DesiredCapabilities dcap = new DesiredCapabilities();
dcap.setCapability("pageLoadStrategy", "eager");
FirefoxOptions opt=new FirefoxOptions();
opt.merge(dcap);
WebDriver driver = new FirefoxDriver(opt);
System.out.print("Driver loaded successfully");
driver.get("https://www1.nseindia.com/live_market/dynaContent/live_watch/pre_open_market/pre_open_market.htm");
waitForLoad(driver);
Select dropdown = new Select(driver.findElement(By.id("selId")));
waitForLoad(driver);
dropdown.selectByValue("fo");
waitForLoad(driver);
}
public static void main(String[] args)
{
FirstSeleniumTest ft=new FirstSeleniumTest();
ft.launchBrowser();
}
}