Reputation: 3580
In this program, I want to extract text from a list of WebElements in a child window, return to the parent window, and enter that text into a text field. The program works correctly for the first index, but it does not produce the desired output for any other indexes.
WebDriver driver = new ChromeDriver();
driver.get("https://rahulshettyacademy.com/angularpractice/");
driver.manage().window().maximize();
driver.switchTo().newWindow(WindowType.TAB);
Set<String> handles = driver.getWindowHandles();
Iterator<String> it = handles.iterator();
String parentWinid = it.next();
String childwindow = it.next();
driver.switchTo().window(childwindow);
driver.get("https://rahulshettyacademy.com/");
String courseName = driver.findElements(By.cssSelector("a[href*='https://courses.rahulshettyacademy.com/p']")).get(3).getText();
driver.switchTo().window(parentWinid);
driver.findElement(By.cssSelector("[name='name']")).sendKeys(courseName);
Upvotes: 0
Views: 21