I am writing automation scripts for Dynamics 365 using Selenium Webdriver with C#. All is good till I login and visit first page (a list). Test script clicks on one item in first page and page navigates to another page (ok) Now, when I try to read any field in next page I cannot. I found that

string pageSource = driver.PageSource; // returns source from previous page,
string pageUrl = driver.Url; // returns correct/current url of the browser.

As mentioned in https://sqa.stackexchange.com/a/24979/34538 I have waited enough for the page to be loaded completely before accessing it.

To add: I tested by accessing an object in previous page which is not in current page. And I could read and click it.

  • Can you run "document.documentElement.outerHTML" on the browser console after reaching the desired page and check if this gives you the desired result. Sep 3 '18 at 7:10
  • I tried your suggestion. I got the html content that I expect. But I did not get any of the fields, rather I got html code related to menus and status bar only. I can use developer toolbar though. Just trying to understand what purpose does "document.documentElement.outerHTML" solve. Sep 4 '18 at 1:09
  • The getPageSource returns the string serialization of the DOM of the current browsing context. This is internally implemented by calling "document.documentElement.outerHTML" on the page. In this case I would suggest talk to the dev team why you are not getting the entire DOM when calling the "document.documentElement.outerHTML". Sep 4 '18 at 5:27

Before accessing the page source, I refreshed the driver.


This refreshes the DOM element too, (I guess).

  • Have you solved your issue with this solution?
    – Alexey R.
    Oct 17 '18 at 9:22
  • Yes @AlexeyR. This solution solved the issue. Thanks. Oct 21 '18 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.