Reputation: 3728
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?
Upvotes: 2
Views: 3676
Reputation: 50819
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");
Upvotes: 5