有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (4) 个答案

  1. # 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. # 2 楼答案

    试试下面的吼声xpath

    driver.findElement(By.xpath("//div[@class='modal-footer']//button[contains(@class,'btn-default')]")).click();
    
  3. # 3 楼答案

    By.xpath(".//button[.='/"Submit/"']) 
    

    By.xpath(".//button[@class='btn btn-default']) 
    

    如果找到了但单击无效,请尝试其他注释中的javascript

  4. # 4 楼答案

    我想你能识别出元素。但是,我们无法单击该按钮。 尝试使用以下选项

    1. 使用WebDriverWaitelementToBeClickable单击元素
    WebDriverWait wait = new WebDriverWait(driver, 30);
    WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default")));
    elementBtn.click();
    
    1. 使用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();
    
    
    1. 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.