Selenium WD - get value of disabled input

后端 未结 1 1394
北荒
北荒 2020-12-11 05:12

I\'m trying to get value of a disabled (disabled=\"disabled\") field, but it returns an empty string.

I have tried: .Te

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 05:27

    If you tag is like this -

    
    

    Your code should be -

    WebElement.getAttribute("disabled")
    

    or

    WebElement.getAttribute("id")
    

    Make sure your code is correct. If this does not work please post the HTML code you are using.

    For this tag -

    
    

    To get the value attribute -

    String value = driver.findElement(By.id("j_idt93:j_idt93")).getAttribute("value");
    

    value must be Pārtraukts

    Let me know if have any problems.

    If this does not work you may have to use the javascript executor -

    String value =  (String)((JavascriptExecutor) driver).executeScript("Java script query  in here to return value","");
    

    Your query should be -

    return document.getElementById("j_idt93:j_idt93").getAttribute("value");
    

    0 讨论(0)
提交回复
热议问题