gpt4 book ai didi

java - 选择菜单时出错

转载 作者:行者123 更新时间:2023-12-01 14:55:15 24 4
gpt4 key购买 nike

下面是为 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] 失败:“sample.keyword.FeeToPayTest”-sample.keyword.FeeToPayTest.testOpenApplication() 在 9033 毫秒内完成[VerboseTestNG] org.openqa.selenium.ElementNotVisibleException:驱动程序尝试单击元素的点未滚动到视口(viewport)中。 (警告:服务器未提供任何堆栈跟踪信息)[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'

最佳答案

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

关于java - 选择菜单时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14365701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com