How to get Inspect Element code using Selenium WebDriver

前端 未结 2 957
孤独总比滥情好
孤独总比滥情好 2020-12-16 02:40

I\'m working in selenium with Firefox browser.

The Html code shown in View Source (CTRL+U) is different from the html code i see when inspecting the elements in Firef

2条回答
  •  無奈伤痛
    2020-12-16 03:23

    There are some fundamental difference between the markup shown through View Source i.e. using ctrl + U and the markup shown through Inspector i.e. using ctrl + shift + I.

    Both the methods are two different browser features which allows users to look at the HTML of the webpage. However, the main difference is the View Source shows the HTML that was delivered from the web server (application server) to the browser. Where as, Inspect element is a Developer Tool e.g. Chrome DevTools to look at the state of the DOM Tree after the browser has applied its error correction and after any Javascript have manipulated the DOM. Some of those activities may include:

    • HTML error correction by the browser
    • HTML normalization by the browser
    • DOM manipulation by Javascript

    In short, using View Source you will observe the Javascript but not the HTML. The HTML errors may get corrected in the Inspect Elements tool. As an example:

    • With in View Source you may observe:

      The title

    • Whereas through Inspect Element that would have corrected as:

      The title

    getPageSource() always returns the markup obtained through View Source.

提交回复
热议问题