java - selenium 单击指向新选项卡的链接后,他看不到按钮和字段
问题描述
我的问题如下:我点击在浏览器中打开一个新标签的链接,我切换到这个标签,我想点击该字段来输入文本。不幸的是,它返回给我:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='nameFields']"}
我尝试了各种方法来关闭第一个选项卡(tabs.get(0))。
public exampleMethod() {
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(0));
System.out.println("tab 0: " + driver.getTitle());
driver.close();
driver.switchTo().window(tabs.get(1));
System.out.println("tab 1: " + driver.getTitle());
//driver.navigate().refresh();
//driver.findElement(By.xpath("//*[@id='nameInput']")).sendKeys("qwerty");
nameInput.sendKeys("qwerty");
submit.click();
return this;
}
There is no problem with listing the page titles.
解决方案
Bbefore nameInput.sendKeys("qwerty"),通过下面的代码使用wait
WebElement we = new WebDriverWait(driver, 25).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='nameInput']")));
推荐阅读
- python - 从字符串序列创建 Python lambda 函数
- macos - 如何在 Mac 上运行 install.py 以在 MATLAB 中安装 MOSEK?
- linux - minion 需要交互式身份验证
- reactjs - 使用 Styled Components 和 Polish 如何包含一个函数作为颜色?
- reactjs - Meteor + React - 访问文档时加载 vs 404
- python-3.x - 如何在 Python 3 中循环创建单独的 PD 数据帧
- javascript - Javascript客户端从服务器获取响应
- python - 切片多索引列数据框以获得新的数据框
- python - 修复文本小部件大小
- java - 在 Java 中实现快速排序