-2

After clicking a button it redirect to another webpage associated with it. when i write code to select object in the new page i am not able select field in the new page

public class trail {

public static void main(String[] args) throws InterruptedException { 
    
    System.setProperty("webdriver.chrome.driver","C:\\Users\\Toshiba\\Desktop\\selenium\\chromedriver_win32 (2)\\chromedriver.exe");
        ChromeDriver driver=new ChromeDriver();
        driver.get("https://orgd8994c71.crm8.dynamics.com/main.aspx?appid=e474bdc4-6835-ed11-9db1-002248d5d2d5&pagetype=entityrecord&etn=opportunity&id=818c1b86-0565-4021-9b82-cd67fac340a9");
        Thread.sleep(3000);
        //maximize window screen
        
        driver.manage().window().maximize();
        //user id
        WebElement username = driver.findElement(By.xpath("//input[@type='email']"));
        username.sendKeys("gokul87141@gmail.com");
        //user id button
        WebElement next = driver.findElement(By.xpath("//input[@type='submit']")); next.click();
        Thread.sleep(2000);
        //password
        WebElement password = driver.findElement(By.xpath("//input[@id='i0118']"));
        password.sendKeys("Youaregreat!@#");
        Thread.sleep(2000);
        //password button
        WebElement next1 = driver.findElement(By.xpath("//input[@type='submit']")); next1.click();
        Thread.sleep(2000);
        //next button
        WebElement next2 = driver.findElement(By.xpath("//input[@id='idSIButton9']")); next2.click();
        Thread.sleep(22000);
      //click button
         WebElement next21 = driver.findElement(By.xpath("//*[@id=\"opportunity|NoRelationship|Form|new.opportunity.Command0.Command10-button\"]/span/span[2]")); next21.click();
        Thread.sleep(6000);
        //switch to option
        ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
        driver.switchTo().window(tabs.get(tabs.size()-1));
        
        
        //second click button
         WebElement next22 = driver.findElement(By.xpath("/html/body/button")); next22.click();
        Thread.sleep(6000);
               
    }

}

1 Answers1

0

After clicking the element opening a new tab you need to switch the driver to that tab. Selenium will not do it automatically.
This can be done with the following code:

ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(tabs.size()-1));

After that you will be able to continue on the new tab with your test flow.

Prophet
  • 32,350
  • 22
  • 54
  • 79