Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 关闭随机';弹出窗口'; 我已经创建了运行相同时间的WebDriver测试 一些测试显示“PopupX”将在30秒后出现 在某些测试中,“PopupX”将在60秒时出现 在一些测试中,“PopupX”将在35秒时出现_Java_Maven_Selenium_Selenium Webdriver - Fatal编程技术网

Java 关闭随机';弹出窗口'; 我已经创建了运行相同时间的WebDriver测试 一些测试显示“PopupX”将在30秒后出现 在某些测试中,“PopupX”将在60秒时出现 在一些测试中,“PopupX”将在35秒时出现

Java 关闭随机';弹出窗口'; 我已经创建了运行相同时间的WebDriver测试 一些测试显示“PopupX”将在30秒后出现 在某些测试中,“PopupX”将在60秒时出现 在一些测试中,“PopupX”将在35秒时出现,java,maven,selenium,selenium-webdriver,Java,Maven,Selenium,Selenium Webdriver,你知道身份证 弹出窗口总是有一个唯一的Id“X”来关闭应用程序,甚至不同的弹出窗口也有相同的“X”关闭选项 是否有人知道一种持续搜索和关闭“一种形式的连续轮询”的方法,如果弹出窗口在任何测试用例中随时出现,该方法将关闭弹出窗口? 我知道下面列出的方法有效,可以成功关闭弹出窗口: public void closeGiveawayPopup() throws InterruptedException { WebDriverWait wait = new WebDriverWait(driver,

你知道身份证

  • 弹出窗口总是有一个唯一的Id“X”来关闭应用程序,甚至不同的弹出窗口也有相同的“X”关闭选项

  • 是否有人知道一种持续搜索和关闭“一种形式的连续轮询”的方法,如果弹出窗口在任何测试用例中随时出现,该方法将关闭弹出窗口?

  • 我知道下面列出的方法有效,可以成功关闭弹出窗口:

    public void closeGiveawayPopup() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 10);
    try {
        List<WebElement> elements = wait
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector(".close")));
        for (WebElement element : elements) {
            if (element.isDisplayed()) {
                element.click();
                Thread.sleep(1000);
                wait.until(ExpectedConditions.invisibilityOfAllElements(elements));
                Thread.sleep(2000);
            }
        }
    } catch (Exception e) {
        throw (e);
    }
    
    public void closeGiveawayPopup()引发InterruptedException{
    WebDriverWait wait=新的WebDriverWait(驱动程序,10);
    试一试{
    列表元素=等待
    .直到(预期条件。被(CSS选择器(“.close”))延迟的所有事件的出现);
    for(WebElement:elements){
    if(element.isDisplayed()){
    元素。单击();
    睡眠(1000);
    等待.直到(ExpectedConditions.InvisibilityFallElements(elements));
    《睡眠》(2000年);
    }
    }
    }捕获(例外e){
    投掷(e);
    }
    
  • 我尝试在TestNG“BeforeMethod”注释中添加以下方法,但url甚至没有加载:

    public void closeGiveawayPopup() throws Exception {
    try {
        List<WebElement> elements = getDriver().findElements(By.cssSelector(".close"));
        for (WebElement element : elements) {
            if (element.isDisplayed()) {
                element.click();
            }
        }
    } catch (Exception e) {
        throw (e);
    }
    
    public void closegiveawaypoup()引发异常{
    试一试{
    List elements=getDriver().findElements(By.cssSelector(“.close”);
    for(WebElement:elements){
    if(element.isDisplayed()){
    元素。单击();
    }
    }
    }捕获(例外e){
    投掷(e);
    }
    
    }

  • 弹出窗口的详细信息如下所示:


  • Phil,我不认为你做错了什么。@BeforeMethod注释是一条路。唯一需要改进的是包括(如果你还没有的话)分别用于浏览器启动/关闭的@BeforeClass注释。也许,这就是您在上面的描述中提到的“浏览器甚至没有打开”的原因。因此类似这样的情况:

    @BeforeClass    
        public void initialSetup(String browser){
    
            Webdriver driver = new browser ();
            driver.get("https://www.buyagift.co.uk/");
       }
    
    
      @BeforeMethod 
      public void closeGiveAwayPopup(){
      //same as your code 
      }
    
      @Test(priority=1)
      public void makeSureIarrivedOnTheHomePage(){
      titleGrabbed = driver.getTitle().toString();
      titleExpected = "Experience Days and Gifts from Buyagift";
      Assert.assertEquals(titleGrabbed ,titleExpected )
      }
    
      @Test(priority=2)
      public void clickLoginButton(){
      //more actions
      }
    
    @AfterClass
      public void shutDown(){
    
        driver.quit(); 
      }
    
    driver.findElement(By.xpath("//div[@id='competiton_giveaway_popup']//button[@id='close']"));
    
    为了达到你所追求的“连续轮询”效果,我能想到的唯一方法就是让你的@Test非常小(一次一步)。这样希望你能达到预期的效果。所以不要在1@Test下捆绑很多WebDriver操作,因为这会增加弹出窗口出现的风险

    唯一让我困惑的是你的评论“url甚至没有加载”。你确定你抓住了实际的弹出窗口而没有关闭整个窗口吗

    如果是这种情况,或者上述方法不适用于您,请尝试使用Xpath而不是CSS。从屏幕截图中,您需要展开div[@id='competition\u inner\u和outer details'],并在某处找到关闭按钮(可能您正在寻找