最佳答案
您尝试定位的元素位于模态对话框内,因此您必须引发WebDriverWait才能使该元素可单击,并且您可以使用以下选项之一:
css选择器:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default#save"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='modal-footer']//button[@class='btn btn-default' and @id='save']"))).click();
关于java - 无法通过 Selenium 和 WebDriver 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50258137/