reading text from textarea in webdriver

前端 未结 3 1883
别那么骄傲
别那么骄傲 2021-02-13 18:12

I am trying to read text from textarea when writing a webdriver test in Java. For some reason I am getting null back when I use .getAttribute():

            


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

    So finding an element returns a web element. To get the text of the element you have to call getText(), so from above

     WebElement element = wd.findElement(By.id("edit-pi-sample-geo-id"));
     String text = element.getText()
    
    0 讨论(0)
  • 2021-02-13 18:55

    I got this working. Here is the solution-

        WebElement text = wd.findElement(By.id("edit-pi-analytics-tms-id"));
        String textagain = text.getAttribute("value");
    

    I was using the actual value in the textarea in the previous code example i posted which was kinda silly. Thanks guys for your help

    0 讨论(0)
  • 2021-02-13 18:58

    I'm using selenium version 3.4 and using element.getAttribute("value") that work for me. The element.getText() would return empty value for TextArea.

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