In order to get a browser window title, the web driver must switch to the window by its Handle id:
string title = driver.SwitchTo().Window("Handle ID").Title;
I am testing opening multiples windows and I need to get a window's title by only having the Handle Id and also without the web driver focusing the selected window bringing it to the front. This is what I have:
public string getWindowTitleByHandleId(string handleId){
string[] handles = driver.WindowHandles.ToArray();
for (int i = 0; i < handles.Length; i++)
{
if (handles[i] == handleId) { return driver.SwitchTo().Window(handles[i]).Title}
}
return "";
}
Is there a better way to achieve this?