无法单击“设置”链接

时间:2016-11-02 15:34:30

标签: selenium-webdriver

场景是: 1.登录谷歌日历 2.单击页面右上角的设置图标 3.单击设置链接

当我使用firebug中的xpath搜索元素时,我能够为每个元素找到1个匹配项。但在脚本执行期间,它可以单击设置图标,但无法单击设置链接。以下是要查找的代码,然后点击设置图标和设置链接

    //Select the settings icon : This is working
    driver.findElement(By
                            .xpath(".//*[@id='mg-settings']/div")).click();

//click on Settings link : This is not working even though element is available
        driver.findElements(By.xpath("//*[@id=':k']/div[text()=\"Settings\"]")).click();

1 个答案:

答案 0 :(得分:0)

注意" s"最后(您使用的是driver.findElement s 而不是driver.findElement)。可能这只是一个错字。

此外,我不建议使用绑定到":k"等ID。它们是动态的,可以随时更改。

根据Google日历结构,我建议您尝试以下操作:

driver.findElement(By.xpath("//*div[contains(@class, 'goog-menuitem')]/div[contains(@class, 'goog-menuitem-content') and text() = 'Settings']")).click();
相关问题