我需要单击“数据库”按钮。我尝试这段代码:
driver.switchTo().frame("frame_content");
wait.until(visibilityOfElementLocated(By.id("topmenucontainer")));
driver.findElement(By.linkText("server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01"));
但即使提及当前链接也对我没有帮助,我有异常(exception):
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"partial link text","selector":"server_databases.php?token=65...
我做错了什么?我怎样才能用 XPath 矿石以其他方式做到这一点?
最佳答案
试试这个:
driver.findElement(By.xpath("//a[contains(@href,'server_databases.php?token=')]"));
您的 token 可能每次都会生成,因此让它查找是否包含部分链接。
关于java - 如何使用 WebDriver 查找按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21866395/