selenium - 单击元素不调用下一个事件
问题描述
问题是当单击元素时,它没有打开它应该打开的弹出窗口。浮动菜单消失,因此在下一步失败
我用了
System.out.println("RateType_selected");
验证点击
(此命令单击的元素位于浮动菜单上,如果页面滚动则消失)
我没有滚动页面只是单击元素以打开弹出窗口,但单击时菜单消失
// Command Element to open the floating menu
driver.findElement(By.cssSelector(".create-for-no-item .create-new.add-rate")).click();
// Command to click on the floating menu element to open popup
driver.findElement(By.xpath("//li[@class='new-item popup-opener active-new-list-item']//span[@class='new-text'][contains(text(),'Recurring Rate')]")).click();
driver.findElement(By.cssSelector(".action-dropdown-button:nth-child(3) > .create-new")).click();
// Tried Javascript as well
WebElement addRatetype = driver.findElement(By.cssSelector(".action-dropdown-button:nth-child(3) > .create-new"));
js.executeScript("arguments[0].click();", addRatetype);
((JavascriptExecutor) driver).executeScript("arguments[0].click();",driver.findElement(By.cssSelector(".action-dropdown-button:nth-child(3) > .create-new")));
// 另外,尝试了 try catch
try {
driver.findElement(By.cssSelector(".action-dropdown-button:nth-child(3) > .create-new")).click();
System.out.println("Clicked on Recurring rate");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
解决方案
我使用了一个新的定位器来查找元素,现在每次都舔
driver.findElement(By.xpath("//div[@class='create-for-no-item product-create rate sdfcddm need-to-hide-dropdown-panel']//li[2]")).click();