【问题标题】:Why My Popup Cancel Button is Not Clickable?为什么我的弹出式取消按钮不可点击?
【发布时间】:2018-06-27 09:53:26
【问题描述】:

我想处理此弹出窗口并单击取消按钮。我试过了,但它是不可点击的

弹出窗口的图像

我还添加了 Html 图片,请检查并告诉我解决方案

HTML 代码图像

测试用例在 Selenium 中传递,但没有点击。我将附上 Selenium 代码。

    package Backendsite;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

public class SkipTest {
  @Test
  public void f() 
  {
      System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");

      //Setting To Open Incoginoto Window
      ChromeOptions options = new ChromeOptions();
      options.addArguments("-incognito");
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      capabilities.setCapability(ChromeOptions.CAPABILITY, options);
      WebDriver chromedriver=new ChromeDriver(capabilities);

      chromedriver.manage().window().maximize();

      //Opening The WebSite
      chromedriver.get("xxxxxxxxxxxxxxxx");


      chromedriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

      Pomsite p1 = PageFactory.initElements(chromedriver, Pomsite.class);

      Select s1 = new Select(p1.getE1());
      s1.selectByVisibleText("xxxxxxxxxx");

      p1.getE2().click();

      try
      {
      Actions a1 = new Actions(chromedriver);
      a1.moveToElement(p1.getE3()).click(p1.getE4()).build().perform();
      }
      catch(Exception e)
      {
          System.out.println("Can't Click");
      }

      chromedriver.close();
  }
}

Pageobject 模型类的第二个代码:

 package Backendsite;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class Pomsite 
{

    public WebElement getE1() {
        return e1;
    }

    public WebElement getE2() {
        return e2;
    }

    public WebElement getE3() {
        return e3;
    }

    public WebElement getE4() {
        return e4;
    }


    @FindBy(id="ddlstore")
    private WebElement e1;

    @FindBy(xpath="//input[@id='CustomPaging_GridView_gv_edit1_0']")
    private WebElement e2;

    @FindBy(xpath="/html/body/div[1]/div/div/div[3]")
    private WebElement e3;

    @FindBy(xpath="/html/body/div[1]/div/div/div[3]/button[2]")
    private WebElement e4;



}

我的取消按钮弹出的 HTML 代码

<div class="modal-footer">
                <span id="prcid" style="display:none;">processing...</span>
                <button type="button" id="skipok" onclick="skipoverall(this)" class="btn btn-primary" data-id="10514438996">Ok</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
            </div>

PS:我也尝试了警报和确认弹出窗口,它不起作用。

【问题讨论】:

  • 请将 html 发布为有问题的格式化代码,而不是图片
  • @NitinSingh 我已按照您的要求附上了取消按钮的 HTML 代码。
  • 上述弹窗是否会在某些操作后打开?
  • 如果不工作,它给出的例外是什么

标签: html selenium selenium-webdriver


【解决方案1】:

试试这个:

@FindBy(xpath="//div[@class = 'modal-footer']/button[@data-dismiss = 'modal']")
private WebElement cancelButton;

Actions a1 = new Actions(chromedriver);
a1.moveToElement(p1.getCancelButton()).click(p1.getCancelButton()).build().perform();

PS 我想我找到了问题所在,为什么你转到E3,却点击E4?可以这样做:

Actions a1 = new Actions(chromedriver);
a1.moveToElement(p1.getE4()).click(p1.getE4()).build().perform();

【讨论】:

  • 实际上,首先我将元素移到了仅用于 E3 的
    函数,然后我移动并单击了我提到的 E4 @Andrei Suvorkov 的特定元素
【解决方案2】:

请通过删除 try - catch 块尝试以下操作。

    WebDriverWait wait=new WebDriverWait(chromedriver,20);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[text()='Cancel']")));
    chromedriver.findElement(By.xpath("//button[text()='Cancel']")).click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多