无法单击鼠标悬停时出现的子菜单

时间:2018-02-15 04:58:33

标签: selenium-webdriver mouseover

我尝试过以下方法,但没有运气

尝试1:

WebElement profile =  dr.findElement(By.xpath("//ul[@id='wp-admin-bar-top-secondary']//a[@title='My Account']"));
WebElement logout = dr.findElement(By.xpath("//ul[@id='wp-admin-bar-user-actions']/li["+i+"]/a"));
Actions action = new Actions(dr);
action.moveToElement(profile).perform();
action.moveToElement(logout).click().perform();

尝试2:

Actions action = new Actions(dr);
action.moveToElement(profile).click(logout).perform();

尝试3:

Actions action = new Actions(dr);
action.moveToElement(profile).perform();

List<WebElement> l = dr.findElements(By.xpath(".//*[@id='wp-admin-bar-user-actions']/li"));
for(int i=0;i<=l.size()-1;i++){
    WebElement s = l.get(i);
    System.out.println(l.get(i).getText());
    if(s.getText().equalsIgnoreCase("logout")){
        //  WebElement logout = dr.findElement(By.xpath("//ul[@id='wp-admin-bar-user-actions']/li["+i+"]/a"));
            action.moveToElement(dr.findElement(By.xpath("//ul[@id='wp-admin-bar-user-actions']/li["+i+"]/a"))).click().build().perform();
            //s.click();
        }
    }

请帮助我,这可能是什么问题。

0 个答案:

没有答案