new to selenium, take it easy on me :)
When i try to interact with a switched to page, the child page disappears and the parent page is brought back into focus. I have had a little google but am struggling to find a similar question.
public static void Initialize()
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--start-maximized");
Instance = new ChromeDriver(DRIVER_PATH, chromeOptions);
Instance.Manage().Window.Maximize();
TurnOnWait();
}
IDriver is just a wrapper I use (have included initialise method for completeness).
public static void SwitchNextWindow(IWebElement windowOpener) {
//Click the button that opens the new window
windowOpener.Click();
//Switch to new window
string newWindowHandle = Instance.WindowHandles.Last();
var newWindow = Instance.SwitchTo().Window(newWindowHandle);
//This works
newWindow.Manage().Window.Maximize();
//The title is stored correctly but the window moves behind the parent
string expectedNewWindowTitle = newWindow.Title;
//This of course will not be found as we are now focused on the parent window
var okButton = Instance.FindElement(By.Id("id_ok_submit"));
//Parent page is shown at this point and errors out as element not found.
okButton.Click();
//If i manually bring the child page into focus (minimize parent) I can step over this code and it will find the button.
}
//If i manually bring the child page into focus (minimise parent) I can step over this code and it will find the button.
//This happens for a find element call also and not just getting the title.
Many thanks guys.
Aucun commentaire:
Enregistrer un commentaire