Get HTML Source of WebElement in Selenium WebDriver using Python

后端 未结 14 1765
误落风尘
误落风尘 2020-11-22 13:45

I\'m using the Python bindings to run Selenium WebDriver:

from selenium import webdriver
wd = webdriver.Firefox()

I know I can grab a webel

14条回答
  •  悲哀的现实
    2020-11-22 14:18

    InnerHTML will return element inside the selected element and outerHTML will return inside HTML along with the element you have selected

    Example :- Now suppose your Element is as below

    AB
    

    innerHTML element Output

    AB
    

    outerHTML element Output

    AB
    

    Live Example :-

    http://www.java2s.com/Tutorials/JavascriptDemo/f/find_out_the_difference_between_innerhtml_and_outerhtml_in_javascript_example.htm

    Below you will find the syntax which require as per different binding. Change the innerHTML to outerHTML as per required.

    Python:

    element.get_attribute('innerHTML')
    

    Java:

    elem.getAttribute("innerHTML");
    

    If you want whole page HTML use below code :-

    driver.getPageSource();
    

提交回复
热议问题