Prabu Prabu - 1 month ago 13
Javascript Question

ng model GetText() method issue Selenium WebDriver with Java

Action:
getting the value from the text box using GetText() method with using Selenium webdriver

HTMl code

<input class="form-control ng-pristine ng-valid dirty ng-touched" type="text" placeholder="Search Query" my-enter="SaveBind('Search');" ng-model="Query.SearchTerm" name="headerSearch">


above one is an Input type with text control, so i want extract the value from the text box

my Xpath:

@FindBy(how = How.XPATH, using = "//input[@ng-model='Query.SearchTerm']")
public WebElement searchQuery;


if i used getText method i am getting empty value

String query = searchQuery.getText();


but when we pass the value thru send key its working perfectly and enterd value paste in the control

searchQuery.sendKeys("Welcome");


my doubt:
entered values are not shown in the HTML tag? then how can i extract the value from the text box?
is it possible to do an automate the Angular Js?

Screen shot attachedenter image description here

Guy Guy
Answer

No, entered values are not shown in the html. To get the entered value you need to use getAttribute() method

String query = searchQuery.getAttribute("value");
Comments