Unable to read text from textbox using gettext() of selenium webdriver?

前端 未结 4 725
醉酒成梦
醉酒成梦 2020-12-16 15:37

I can\'t read dates from ajax calendar control after date selection

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx

I don

相关标签:
4条回答
  • 2020-12-16 16:04

    The call to get the input text should be:

    driver.findElement(By.id("ctl00_SampleContent_Date5")).getAttribute("value");
    

    Don't ask me why, it's just the way it always has been. By typing into an input element, you are changing its value attribute.

    0 讨论(0)
  • 2020-12-16 16:09

    driver.findElement(By.id("ctl00_SampleContent_Date5")).getAttribute("value");

    it always return the values that has been written inside textbox

    0 讨论(0)
  • 2020-12-16 16:16

    I think Selenium is aligned to how DOM works but still, I don't think any user expect that getText will not return what is visible in the screen. Both innerHTML, and innerText return empty string so that explain why getText doesn't return anything.

    I think Selenium should simplify oddities of the DOM. In other words, getText() should return what a user see in the screen, then if a use case want the real innerText, they can call other API.

    0 讨论(0)
  • 2020-12-16 16:16

    In this case you should invoke getAttribute("value").

    I believe getText() only returns the inner text of the element, not the inputted value.

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