0
votes

Selenium web driver finds element unable to find input field on the web page I tried this each and every option XPath, by CSS, by name. the testing site on the local environment.

HTML:

<input class="form-control ng-pristine ng-untouched ng-valid ng-empty" ng-model="email" placeholder="Username" aria-describedby="username" type="text">

xpath:

/html/body/div[2]/div/div/div[1]/div/div/div[2]/div/form/div[2]/div/div/input

css selector:

html.no-js.ng-scope body.pace-done.full-width div#wrapper div.page-wrapper.white-bg.ng-scope div.wrapper.wrapper-content.ng-scope div.login-bg.ng-scope div.container div.row div.col-sm-6.col-sm-offset-3.col-md-4.col-md-offset-4 div.login-form form.ng-pristine.ng-valid div.col-sm-12.plr10px div.form-group div.input-group input.form-control.ng-pristine.ng-untouched.ng-valid.ng-empty

driver.findElement(By.name("username"))

3
there is no name attribute to the html you are trying to identiy, also xpath and css is too long. not a good thing.Gaurang Shah
i tired with xpath and css also but it doesn't workAjay Kumar
It seems the application is angular. Did you handled waits correctly?santhosh kumar

3 Answers

2
votes

Here is the Answer to your Question:

As per the HTML you provided, you can use the following xpath to identify the element-

WebElement element = driver.findElement(By.xpath("//input[@ng-model='email' and @placeholder='Username']"));

Incase you are facing an ElementNotVisible exception you can induce ExplicitWait to wait for the element to be clickable as follows:

WebDriverWait wait7 = new WebDriverWait(driver, 10);
WebElement element7 = wait7.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@ng-model='email' and @placeholder='Username']")));
element7.click();

Let me know if this Answers your Question.

0
votes

Try this, this should work.

WebElement emailInput = new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[ng-model='email']")));
0
votes
JavascriptExecutor je = (JavascriptExecutor) driver;

WebElement Username = driver.findElement(By.xpath("//*[@placeholder='Username' and @type='text'"]));

je.executeScript("arguments[0].scrollIntoView(true);",Username);

Username.sendKeys("Name");