代码之家  ›  专栏  ›  技术社区  ›  koushick

为什么我的弹出取消按钮不可点击?

  •  3
  • koushick  · 技术社区  · 8 年前

    我想处理这个弹出窗口并点击取消按钮。我试过了,但不能点击

    弹出式菜单的图像

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

    HTML代码的图像

    测试用例正在传入Selenium,但它没有单击。Down I will be attached the Selenium code also.

    包后端站点; 导入java.util.concurrent.timeUnit; 导入org.openqa.selenium.webdriver; 导入org.openqa.selenium.chrome.chromedriver; 导入org.openqa.selenium.chrome.chromeoptions; 导入org.openqa.selenium.interactions.actions; 导入org.openqa.selenium.remote.desiredCapabilities; 导入org.openqa.selenium.support.pagefactory; 导入org.openqa.selenium.support.ui.select; 导入org.testng.annotations.test; 公共类滑雪运动员{ @测试 公共作废f() { system.setproperty(“webdriver.chrome.driver”,“f:\\new folder\\chromedriver.exe”); //设置为打开incoginoto窗口 chromeoptions options=new chromeoptions(); options.addarguments(“-incognito”); DesiredCapabilities Capabilities=DesiredCapabilities.chrome(); capabilities.setcapability(chromeoptons.capability,选项); WebDriver Chromedriver=新Chromedriver(功能); chromedriver.manage().window().maximize(); //打开网站 chromedriver.get(“XXXXXXXXXXXXXX”); chromedriver.manage().timeouts().implicitlywait(20,timeUnit.seconds); pomsite p1=pagefactory.initmelements(chromedriver,pomsite.class); 选择s1=新选择(p1.gete1()); s1.按可见文本(“XXXXXXXXX”)选择; p1.gete2()。单击(); 尝试 { 动作A1=新动作(Chromedriver); a1.moveToElement(p1.gete3())。单击(p1.gete4()).build().perform(); } catch(异常E) { system.out.println(“无法单击”); } chromedriver.close(); } }

    
    

    pageObject模型类的第二个代码:

    包后端站点; 导入org.openqa.selenium.webelement; 导入org.openqa.selenium.support.findby; 公共级浮渣 { 公共WebElement gete1()。{ 返回e1; } 公共WebElement gete2()。{ 返回e2; } 公共WebElement gete3()。{ 返回E3; } 公共WebElement gete4()。{ 返回E4; } @findby(id=“ddlstore”)。 私有WebElement e1; @findby(xpath=“//input[@id='custompaging_gridview_gv_edit1_0']”) 私有WebElement e2; @findby(xpath=“/html/body/div[1]/div/div/div[3]”) 私有WebElement e3; @findby(xpath=“/html/body/div[1]/div/div/div[3]/button[2]”) 私有WebElement e4; }

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

    <div class=“modal footer”>
    <span id=“prcid”style=“display:none;”>正在处理…</span>
    <button type=“button”id=“skipok”onclick=“skipoverall(this)”class=“btn btn primary”data id=“10514438996”>确定</button>
    <button type=“button”class=“btn btn secondary”data disclose=“modal”>取消</button>
    </DIV>
    

    PS:我还尝试了警报和确认弹出,它不工作。

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

    HTML代码的图像

    Image For HTML Code

    测试用例正在传入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>
    

    附言:我还尝试了警报和确认弹出,它不工作。

    2 回复  |  直到 8 年前
        1
  •  0
  •   Andrei Suvorkov    8 年前

    @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();
    

    E3 E4 是吗?可以这样做:

    Actions a1 = new Actions(chromedriver);
    a1.moveToElement(p1.getE4()).click(p1.getE4()).build().perform();
    
        2
  •  0
  •   Subburaj    8 年前

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