java - Selenium Web Driver FindElement() 方法不起作用(NoSuchElementException)
问题描述
所以我的问题很简单。这是我的代码:
driver.findElement(By.id("j_username")).sendKeys("nk");
driver.switchTo().frame(0);
driver.findElement(By.id("j_password")).sendKeys("1");
第一个 findElement() 方法可以正常工作,但是当我第二次尝试使用它时,我得到了这个错误:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"j_password"}
所有 id 都是正确的。
解决方案
试试这个:
driver.findElement(By.id("j_username")).sendKeys("nk");
driver.findElement(By.name("j_password")).sendKeys("1"); // find by name
第二个元素没有id,至少在HTML
你提供的。
推荐阅读
- scala - 任务“程序集”失败,并出现“[错误](程序集)java.nio.file.InvalidPathException: Trailing char < > at index 121”
- c - 在动态内存分配中为字符数组赋值时出现意外结果
- image - 我想将图像限制为 16 种颜色,但仅限于特定较大颜色集的颜色
- wordpress - 将 Woocommerce 自定义占位符图像链接到产品页面
- sql-server - Django 在 SQL Server 上使用 ntext 计算子对象
- node.js - MongoDB如何填充
- ios - UIApplicationProtectedDataWillBecomeUnavailable 通知 VS applicationProtectedDataWillBecomeUnavailable 委托
- python - Pipenv 安装运行时错误:未创建或指定位置
- python - Python:如何迁移在数据框中将 SVM 函数应用于分组依据的 R 函数
- excel - 当我从另一个宏“调用”它时宏不起作用,但当我单独选择它时它确实起作用