Currently, I am working on automating a Web application using Selenium in C#. My task involves clicking on a link on the home page which redirects me to another page. To switch to this new page, I have implemented the following code:
string parent = webDriver.CurrentWindowHandle;
while (webDriver.WindowHandles.Count <= 1) ; // waiting for new tab
foreach (string handle in webDriver.WindowHandles)
{
if (handle != parent)
{
webDriver.SwitchTo().Window(handle);
break;
}
}
This new page contains only two links that allow users to select their role. Upon clicking the second link, a JavaScript function modifies the entire page and loads new data on the same page. However, even after the page has changed, the webdriver continues to return the same old page source with just the initial two links. The title of the changed page is updated correctly by the browser, but the webdriver does not provide the latest page source as expected.
After reading the documentation, it seems that IE webdriver does not always return the most up-to-date page source. Given this limitation, I conducted a small test using the
webdriver.FindElements(By.XPath(//a);
method to fetch tags from the new page. Unfortunately, instead of retrieving tags from the modified page, the driver returned tags from the original page containing the selection links. This has left me puzzled and unsure why the driver is failing to deliver the latest tags from the updated page.
I am stuck on this issue and would sincerely appreciate any guidance or assistance. Thank you in advance!