Selenium - Get elements html rather Text Value

前端 未结 3 2187
我在风中等你
我在风中等你 2021-02-18 18:35

Via that code i have extracted all desired text out of a html document

private void RunThroughSearch(string url)
{
    private IWebDriver driver;
    driver = n         


        
相关标签:
3条回答
  • 2021-02-18 18:38

    I found the solution from SQA-SO

    IWebDriver driver;
    IJavaScriptExecutor js = driver as IJavaScriptExecutor;
    js.ExecuteScript("document.getElementById("title").innerHTML = "New text!";");
    
    0 讨论(0)
  • 2021-02-18 18:47

    This seemed to work for me, and is less code:

    var element = driver.FindElement(By.ClassName("sa_wr"));
    var innerHtml = element.GetAttribute("innerHTML");
    
    0 讨论(0)
  • 2021-02-18 18:51

    Find the element first, then use IJavaScriptExecutor to get the inner HTML.

    var element = driver.FindElements(By.ClassName("sa_wr"));
    IJavaScriptExecutor js = driver as IJavaScriptExecutor;
    if (js != null) {
        string innerHtml = (string)js.ExecuteScript("return arguments[0].innerHTML;", element);
    }
    
    0 讨论(0)
提交回复
热议问题