Ajay Kumar
Ajay Kumar

Reputation: 41

Selenium driver find element not working

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"))

Upvotes: 0

Views: 10002

Answers (3)

undetected Selenium
undetected Selenium

Reputation: 193338

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.

Upvotes: 2

Mounika Medipelli
Mounika Medipelli

Reputation: 61

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");

Upvotes: 0

Gaurang Shah
Gaurang Shah

Reputation: 12940

Try this, this should work.

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

Upvotes: 0

Related Questions