Get HTML Source of WebElement in Selenium WebDriver using Python

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

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

    This code really works to get JavaScript from source as well!

提交回复
热议问题