单击该元素不会调用下一个事件

时间:2020-03-12 04:51:42

标签: 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();
            }

1 个答案:

答案 0 :(得分:0)

我使用了新的定位器来查找元素,现在每次都点击

 driver.findElement(By.xpath("//div[@class='create-for-no-item product-create rate sdfcddm need-to-hide-dropdown-panel']//li[2]")).click();