Selenium Java to generate alert and navigate to another page using JavascriptExecutor
GD.java
importorg.openqa.selenium.JavascriptExecutor;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeDriver;classGD{publicstaticvoidmain(String[]args){System.setProperty("webdriver.chrome.driver","/home/godarda/drivers/chromedriver");WebDriverdriver=newChromeDriver();driver.manage().window().maximize();driver.get("https://godarda.in/");JavascriptExecutorjse=(JavascriptExecutor)driver;jse.executeScript("window.location = 'https://godarda.in/testapp/'");jse.executeScript("alert('Navigated from home page');");//driver.close();}}
Dear User, Thank you for visitng GoDarda. If you are interested in technical
articles, latest technologies, and our journey further, please follow us on LinkedIn.