硒悬停功能在第二个呼叫中不起作用

时间:2019-08-21 11:07:47

标签: java selenium selenium-webdriver

我需要将光标悬停在工具提示上,然后检查其中的文字以查找其他产品。但是当第二次调用时,hover()函数不会将光标移至工具提示。我怎样才能在以后的通话中使用它?

我尝试了以下操作:

final StringJoiner tooltipIconClassStringJoiner = new StringJoiner(" ");
tooltipIconClassStringJoiner.add(format(MULTI_CART_ENTRY_ID_FORMAT, productCode));
tooltipIconClassStringJoiner.add(MAINTENANCE_SECTION);
tooltipIconClassStringJoiner.add(TOOLTIP_ICON);

final SelenideElement element = $(tooltipIconClassStringJoiner.toString());
element.shouldBe(visible);
element.hover();

final StringJoiner maintenanceTooltipStringJoiner = new StringJoiner(" ");    
maintenanceTooltipStringJoiner.add(format(MULTI_CART_ENTRY_ID_FORMAT, productCode));
maintenanceTooltipStringJoiner.add(format(MAINTENANCE_TOOLTIP, productCode));

$(maintenanceTooltipStringJoiner.toString()).shouldBe(visible);

我还尝试了以下操作:

new Actions(webDriverUtils.getDriver()).moveToElement(element).perform();

但这两个选项仅在第一次调用hover / moveToElement函数时有效。

1 个答案:

答案 0 :(得分:0)

我对Java不熟悉。

但是我认为您应该在第二次hover()之前再次获取元素。

使用For循环包装下面的代码。

// get element that you want to hover first.
Actions(webDriverUtils.getDriver()).moveToElement(element).perform();
相关问题