java Selenium webdriver无法在模式对话框中找到元素 8 月,4 周 Questions & Answers 1606 我在对话框页面上找不到按钮,我尝试使用CSS选择器、XPath,但很简单,我在模式对话框上找不到按钮/文本 我附上了代码的截图 你能推荐什么 谢谢大家!
# 1 楼答案 你可以试试这个: JavascriptExecutor js= (JavascriptExecutor) driver; WebElement webElement=driver.findElement(By.cssSelector("div.modal-footer button.btn.btn-default")); js.executeScript(“arguments[0].click()”, webElement); 希望能有帮助
# 2 楼答案 试试下面的吼声xpath: driver.findElement(By.xpath("//div[@class='modal-footer']//button[contains(@class,'btn-default')]")).click();
# 3 楼答案 By.xpath(".//button[.='/"Submit/"']) 或 By.xpath(".//button[@class='btn btn-default']) 如果找到了但单击无效,请尝试其他注释中的javascript
# 4 楼答案 我想你能识别出元素。但是,我们无法单击该按钮。 尝试使用以下选项 使用WebDriverWait和elementToBeClickable单击元素李> WebDriverWait wait = new WebDriverWait(driver, 30); WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default"))); elementBtn.click(); 使用Action类单击元素李> WebDriverWait wait = new WebDriverWait(driver, 30); WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default"))); Actions action=new Actions(driver); action.moveToElement(elementBtn).click().build().perform(); Java脚本执行器来单击元素李> JavascriptExecutor js= (JavascriptExecutor) driver; js.executeScript("arguments[0].click();", driver.findElement(By.cssSelector("div.modal-footer button.btn.btn-default"))); 注意:如果以上所有选项都不起作用。检查是否有可用的iframe。如果是这样,您需要首先切换到iframe。如下图所示 driver.switchTo().frame("framename"); //name of the iframe. driver.switchTo().frame(0); //you can use index as well.
# 1 楼答案
你可以试试这个:
希望能有帮助
# 2 楼答案
试试下面的吼声
xpath
:# 3 楼答案
或
如果找到了但单击无效,请尝试其他注释中的javascript
# 4 楼答案
我想你能识别出元素。但是,我们无法单击该按钮。 尝试使用以下选项
WebDriverWait
和elementToBeClickable
单击元素李>注意:如果以上所有选项都不起作用。检查是否有可用的
iframe
。如果是这样,您需要首先切换到iframe。如下图所示