java - 在 Angular 站点中,即使 xpath 正确,元素也无法找到错误显示。尝试使用 javascript 执行器仍然无法正常工作
问题描述
输入信用卡号时,它不在框架中并引发错误。请注意,这是一个基于角度的网站。
driver.findElement(
By.xpath("//input[@id='credit-card-number']")
).sendKeys("4111111111111111");
控制台错误
FAILED: orderplace
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id='credit-card-number']"}
(Session info: chrome=84.0.4147.89)
解决方案
尝试使用此代码代码:
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement myinput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='credit-card-number']")));
myinput.sendKeys("4111111111111111");
我添加了wait
'直到输入框可见。一旦它可见,您就可以将文本放入其中。
推荐阅读
- javascript - 切换在地图功能 onClick 内显示特定元素
- prolog - 如何确定 16 谜题的启发式性能?
- reactjs - 如何在 React 导航中获取当前焦点选项卡名称
- ssh - 无法访问 Plesk,错误“无法通过 shm.name 打开或创建共享内存,权限被拒绝”
- android - 发布新更新后 AnroidRuntime 出现致命异常
- karate - 在其他目录上重新使用一项功能时无法转换为地图
- c - 如何将 LibTomCrypt 与 Contiki 一起使用
- dart - 行小部件中的文本换行
- node.js - nodejs http.createServer read url and remove urlprefix
- html - 未捕获(承诺):错误:模板解析错误:在 Angular 6