javascript - 无法找到要单击的元素/使用 Java 在 selenium 中发送 key

标签 javascript java angularjs selenium

我是这个论坛的新人,这实际上是我第一次编码

在代码中我有这部分:

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>

每次我打开 session 时,ID 都会得到不同的数字。 我试试这个:

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

也可以通过 URL 访问:“ocloud.optitex.com” 转到“忘记密码”,我正在尝试找到那里的电子邮件字段,单击它并发送 key

但什么也没发生。我收到此错误:

No such Element Exception , unable to locate element.

对于有关如何单击该字段并发送 key 的任何帮助,我将不胜感激。

最佳答案

在代码中使用隐式等待,以便有足够的时间通过异常定位到它之前的元素

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("abc@gmail.com");
driver.findElement(By.xpath("//button/span[contains(.,'Reset Password')]")).click();

关于javascript - 无法找到要单击的元素/使用 Java 在 selenium 中发送 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43976659/

相关文章:

java - Mockito inOrder.verify() 失败 - "Wanted but not invoked ... wanted anywhere AFTER following interaction"

java - 当 getErrorPath() 返回 "/error"以外的路径时,自定义错误页面不起作用

javascript - AWS API Gateway 未检测到 Angular $resource POST 请求查询参数?

javascript - 跟踪嵌套的 ng-repeat 索引

javascript - 根据主要复选框选择影响辅助单选按钮

javascript - 扩展错误给出错误的堆栈跟踪信息

javascript - 谷歌地图标记显示/隐藏

java - 在 Activity 之间传递可序列化对象的问题

javascript - AngularJS - 检查类型为 "number"的输入是否有值,0 是有效值

javascript - 删除选择的焦点