How to get Inspect Element code using Selenium WebDriver

前端 未结 2 958
孤独总比滥情好
孤独总比滥情好 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:37

    I think your question is answered here.

    The View Source html is what is sent by the server. I think of it as compile time html, or the initial state of the DOM.

    The Inspect Element html could have been updated by ajax responses or javascript so will not necessarily be the same. I think of it as runtime html, or the current state of the DOM.

    The GetAttribute() method queries the current DOM element state. You can return a particular html attribute value directly

    webElement.GetAttribute("class")
    

    or get the whole html string.

    webElement.GetAttribute("innerHTML")
    

提交回复
热议问题