Java 如何解决net.thucydides.core.webdriver.exceptions.element应为VisibleException-selenium
我正在自动生成一个页面,其中我必须选择两个价格,当选择第一个价格时,页面会向下滚动,这就是测试失败的地方,我得到了错误,我已经尝试过显式等待和thread.sleep,但它不起作用。有什么想法吗 这就是错误: net.thucydides.core.webdriver.exceptions.element应可见异常:预期条件失败:等待[[RemoteWebDriver:chrome on XP e64b73bc32012e0506c1b2816cbc2ac2]->xpath://div[@id='divAvailabilityOut']//span[@data bind='html:Price']]以100毫秒的间隔尝试50秒 这是我的代码:Java 如何解决net.thucydides.core.webdriver.exceptions.element应为VisibleException-selenium,java,selenium,testing,junit,automation,Java,Selenium,Testing,Junit,Automation,我正在自动生成一个页面,其中我必须选择两个价格,当选择第一个价格时,页面会向下滚动,这就是测试失败的地方,我得到了错误,我已经尝试过显式等待和thread.sleep,但它不起作用。有什么想法吗 这就是错误: net.thucydides.core.webdriver.exceptions.element应可见异常:预期条件失败:等待[[RemoteWebDriver:chrome on XP e64b73bc32012e0506c1b2816cbc2ac2]->xpath://div[@id=
public void escogerPreioMasCaro() throws InterruptedException {
List<WebElementFacade> listPreciosCaros = findAll(
"//div[@class='availabilityIn box']//span[@data-bind='html: Price']");
String[] strVectorCaros = new String[listPreciosCaros.size()];
int i = 0;
for (WebElementFacade listado : listPreciosCaros) {
System.out.println("Lista Precios Caros" + listado.getText());
strVectorCaros[i] = listado.getText().replaceAll("COP", " ").trim();
i++;
}
System.out.println(Arrays.toString(strVectorCaros).trim());
double[] vec1 = new double[strVectorCaros.length];
for (int g = 0; g < strVectorCaros.length; g++) {
try {
vec1[g] = Double.parseDouble(strVectorCaros[g]);
} catch (NumberFormatException ex) {
System.err.println("Ilegal input");
}
}
// System.out.println(Arrays.toString(vec1));
double precioMayor = vec1[0];
for (int x = 0; x < vec1.length; x++) {
// System.out.println(nombres[i] + " " + sueldos[i]);
if (vec1[x] > precioMayor) { //
precioMayor = vec1[x];
}
}
System.out.println("PrecioCaro" + precioMayor);
String precioMayorString = String.valueOf(precioMayor);
System.out.println("string " + precioMayorString);
for (WebElementFacade listado2 : listPreciosCaros) {
if (listado2.getText().contains(precioMayorString)) {
System.out.println(precioMayorString);
listado2.click();
}
}
Thread.sleep(2000);
}
我要做的是遍历价格序列,将它们分开,只选择数字,然后将它们传递给双类型向量,以便能够比较它们的价格,并选择最昂贵的一个
这是自动化的页面,在选择目的地和旅行日期后出现错误
据我所知,您试图找到并选择最高价格的机票 以下代码示例用于查找和选择从和到图的最大价格:
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
List<Double> pricesDouble = new ArrayList<>();
//Get all prices without currency of FROM Flight section
List<WebElement> fromPrices = driver.findElements(By.cssSelector("#divAvailabilityOut span[data-bind='html: PriceWithoutCurrencySymbol']"));
//To get all prices without currency of TO Flight section use code below
//List<WebElement> toPrices = driver.findElements(By.cssSelector("#availabilityLoadingIn span[data-bind='html: PriceWithoutCurrencySymbol']"));
fromPrices.forEach(e -> {
try {
pricesDouble.add(Double.parseDouble(e.getAttribute("innerText")));
} catch (NumberFormatException ex) {
System.err.println("Ilegal input");
}
});
//Assert.assertTrue(pricesDouble.size()>0, "Get at least one price");
int indexOfMaxPrice = pricesDouble.indexOf(Collections.max(pricesDouble););
//Get clickable element with max price
fromPrices.get(indexOfMaxPrice).findElement(By.xpath("ancestor::div[@class='totalPrice']")).click();
以下是有用的链接:
我不理解这种情况。请提供从您提供的URL开始的手动步骤,以便我们能够尽快到达您获取错误的位置。你在比较什么价格?带圆圈的页面截图会有帮助,因为该网站不是英文的。我的英文不是很好,因此我认为情况解释得不好,但是你能给我你的邮件吗?我给你发了一段舞台视频?