0

以下是为http://www.royalmailgroup.com/的主页编写的课程, 我正在尝试单击“关于我们”链接和 FOI 联系人。

package sample.keyword;

import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.internal.EventFiringMouse;


 public class FeeToPay {

    public static WebElement Menu, SubMenu ;
    public static InternetExplorerDriver driver;
    //public static FirefoxDriver driver;
    public static EventFiringWebDriver eDriver;
    public static EventFiringMouse eMouse;
    public static String xpathMainMenu ="//div[@class='content']/ul/li/span/*";


public void OpenApplication(String Url) throws Exception{

            File file = new File("D:\\Software\\IEDriverServer.exe");
            System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
            driver= new InternetExplorerDriver();

            //driver = new FirefoxDriver();
            eDriver= new EventFiringWebDriver(driver);
            eMouse= new EventFiringMouse(eDriver, null);
            driver.manage().window().maximize();
        try{
            String baseUrl = "http://www.royalmailgroup.com/";
            this.driver.get(baseUrl);

        }
        catch(Exception E){
                throw E;
        }
    }
    public static EventFiringWebDriver getWebDriver(){
        return eDriver;
    }
    public void NavigateTo(String strMenuPath) throws Exception {
    if(strMenuPath == null || strMenuPath.isEmpty())throw new Exception("no menu path mentioned");

    String [] MenuItems = strMenuPath.split("->");
    java.util.List<WebElement> liMenuItems;
    liMenuItems= FeeToPay.getWebDriver().findElements(By.xpath(xpathMainMenu));


    for (int counter =0; counter<MenuItems.length;counter++ ){

        if(counter==0){
            if(liMenuItems.get(counter).getText().equalsIgnoreCase(MenuItems[counter])){
                Locatable item = (Locatable)liMenuItems.get(counter);
                Coordinates c =  item.getCoordinates();
                eMouse.mouseMove(c);
                                }

       }
        if(counter!=0 && counter == MenuItems.length-1 ){
            eDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                WebElement ele = eDriver.findElement(By.linkText(MenuItems[counter]));
                ele.click();
        }
     }

} }

我收到以下错误 [VerboseTestNG] FAILED: "sample.keyword.FeeToPayTest" - sample.keyword.FeeToPayTest.testOpenApplication() 在 9033 毫秒内完成 [VerboseTestNG] org.openqa.selenium.ElementNotVisibleException: 驱动程序尝试的点单击元素未滚动到视口中。(警告:服务器未提供任何堆栈跟踪信息)[VerboseTestNG] 命令持续时间或超时:1.93 秒

我正在使用 Selenium Jar 构建信息:版本:'2.28.0',修订:'18309',系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1', java.version: '1.6.0_37'

4

1 回答 1

1

需要添加 WebDriverWait wait = new WebDriverWait(eDriver,10); wait.until(ExpectedConditions.elementToBeClickable(By.linkText(MenuItems[counter]))); 在点击子菜单之前。

于 2013-01-16T19:29:35.690 回答