简体   繁体   中英

how to handle change in URL in Java Selenium

So I start with a login URL say ("https://LOGIN-URL.com"), I send key values of login credentials with the send keys method, after a few seconds, the credentials are validated and new URL loads ("https://HOME-PAGE.com") with the home page, where I will have to perform some action and then click a button to move onto the next page with a different URL like ("https://transactions-tester123.com")

how do i achecve this with Java Selenium UI automation?

Below i have attached code where i am able to get till the login credentials part, but unable to perform actions in the new URL

        driver.get("https://LOGIN-URL.com");
        driver.manage().window().maximize();
        
        System.out.println(" User trying to login");
        driver.findElement(By.xpath("//input[@id='username']")).sendKeys("hello");
        driver.findElement(By.xpath("//input[@id='password']")).sendKeys("password");
        driver.findElement(By.xpath("//span[@id='ui-id-44']")).click();
        System.out.println("Login successful");
        
        System.out.println("Now user in Home Page");
        

Check the answer in this thread - How to switch to the new browser window, which opens after click on the button?

You should be using driver.getWindowHandles and driver.switchTo() methods

try loading same page/home page/refresh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM