N.P
N.P

Reputation: 33

Can't find element to click on it /send keys in selenium with Java

I'm new in this forum and this is actually my first time ever coding

in the code i have this part:

md-input-container class="md-default-theme md-input-invalid">
label for="input_4">Email</label>
input name="emailField" type="email" ng-model="email" ng-change="resetValidity()" auto-focus="" validate-email="" required="" class="ng-pristine md-input ng-valid-email ng-invalid ng-invalid-required ng-touched" id="input_4" tabindex="0" aria-required="true" aria-invalid="true" style="">
!-- ngIf: forgot_password.emailField.$invalid && forgot_password.$submitted -->
/md-input-container>

the ID everytime i open a session get a different number. i try this:

WebElement emailField = driver.findElement(By.cssSelector("input[name='emailField']"));
emailField.click();
emailField.sendKeys("aa@aa");

can be reach also in the URL: "ocloud.optitex.com" go to "forgot password" i'm trying to find the email field there , click on it and send keys

but nothing happen. i get this error:

No such Element Exception , unable to locate element.

will appreciate any help regarding how i can click on the field and send keys.

Upvotes: 0

Views: 763

Answers (2)

NarendraR
NarendraR

Reputation: 7708

Use Implicit wait in your code to give sufficient time to locate the element before it through exception

driver = new ChromeDriver();    
driver.manage().window().maximize();
driver.get("https://ocloud.optitex.com/#/login/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//button/span[contains(.,'Forgot Password?')]")).click();
driver.findElement(By.xpath("//input[@name='emailField']")).sendKeys("[email protected]");
driver.findElement(By.xpath("//button/span[contains(.,'Reset Password')]")).click();

Upvotes: 1

jova
jova

Reputation: 31

Use xpath;

WebElement emailField = driver.findElement(By.xPath("//input[@name='emailField']"));
emailField.click();
emailField.sendKeys("aa@aa");

Upvotes: 0

Related Questions