Get HTML Source of WebElement in Selenium WebDriver using Python

后端 未结 14 1907
误落风尘
误落风尘 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:08

    There is not really a straight-forward way of getting the html source code of a webelement. You will have to use JS. I am not too sure about python bindings but you can easily do like this in Java. I am sure there must be something similar to JavascriptExecutor class in Python.

     WebElement element = driver.findElement(By.id("foo"));
     String contents = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element); 
    

提交回复
热议问题