【问题标题】:Automated testing using selenium with firefox browser使用 selenium 和 firefox 浏览器进行自动化测试
【发布时间】:2014-03-22 20:57:14
【问题描述】:

我下载了下面的代码并将其用于一些测试,并且 u=它昨天运行但从今天开始代码停止工作。我的测试现在失败了,以前没有发生过。它抛出一个错误,说 org.openqa.selenium.ElementNotVisibleException: element is not current visible so cannot interact with element.

package org.openqa.selenium.example;

//import org.openqa.selenium.browserlaunchers.locators.GoogleChromeLocator;

//import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.*;

import static org.junit.Assert.*;

//import org.openqa.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;
//import org.openqa.selenium.net.UrlChecker;

import static org.junit.Assert.assertEquals;


import org.junit.Test;

public class KongaUrlTest 
{

      private WebDriver driver;
      private String baseUrl;
      //private boolean acceptNextAlert = true;
      private StringBuffer verificationErrors = new StringBuffer();

      @Before
      public void setUp() throws Exception 
      {
        driver = new FirefoxDriver();
        baseUrl = "http://www.konga.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }

      @Test
      public void testFirefoxWebdriver() throws Exception 
      {
        driver.get(baseUrl);
        driver.findElement(By.cssSelector("a.vertnavlink > span")).click();
        try 
        {
          assertEquals("Phones & Tablets | Konga Nigeria", driver.getTitle());
          System.out.println(driver.getTitle());
        } 
        catch (Error e) 
        {
          verificationErrors.append(e.toString());
        }
      }

      @After
      public void tearDown() throws Exception 
      {
        System.out.println(driver.getCurrentUrl());
        driver.quit();

      }



}

【问题讨论】:

    标签: java selenium junit


    【解决方案1】:

    正在显示一个阻止对话框。每次 Selenium 打开新浏览器并导航到该站点时,它可能都会显示。首先关闭该对话框:

    driver.get(baseUrl);
    try
    {
        driver.findElement(By.cssSelector(".fancybox-close")).click();
    }
    catch { }
    driver.findElement(By.cssSelector("a.vertnavlink > span")).click();
    

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 2012-06-01
      • 2021-03-11
      • 1970-01-01
      相关资源
      最近更新 更多