如果
webdriver.findElement(button).click();
投掷
没有这样的元素:无法找到元素: {"method":"xpath","selector":"//按钮[@class='btn btn-lg hideableButton ng-scope' 并包含(@ng-click, 'authenticationCtrl.onSubmitMage()'
这可能是因为元素在 iframe 中或在 DOM 中找不到定位器。
既然你说它存在于 DOM 中,我可能会说,我们这里可能有一个 iframe 问题。
Iframe:
该标签指定内联框架。
内联框架用于在当前文档中嵌入另一个文档 HTML 文档。
在 Selenium 中,我们需要将驱动程序焦点切换到特定的 iframe,以便与 iframe 内的元素进行交互:
driver.switchTo.frame("Frame_ID");
然后你应该能够做到:
webdriver.findElement(By.xpath("//button[text()='Connexion']")).click();
更新1:
有两个同名按钮,我非常确定
xpath
索引会起作用
第一个按钮:
(//button[text()='Connexion'])[1]
第二个按钮:
(//button[text()='Connexion'])[2]
更新2:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//button[text()='Connexion'])[2]"))).click();
我看到了长长的评论树,但没有直接的答案。那么问题出在哪里呢?