【问题标题】:Not able to click on dropdown through xpath or CSS?无法通过 xpath 或 CSS 点击下拉菜单?
【发布时间】:2016-09-01 05:44:18
【问题描述】:

这是一个我无法通过 xpath 或 CSS 选择器点击的下拉菜单。

我的 HTML 代码:-

<button class="userInfo dropdown-toggle btn btn-default" data-reactid=".0.0.0.1:$=11:$1.1" type="button"> <span class="sr-only" data-reactid=".0.0.0.1:$=11:$1.1.0">Toggle dropdown</span> <span class="caret" data-reactid=".0.0.0.1:$=11:$1.1.1"/> <span data-reactid=".0.0.0.1:$=11:$1.1.2" style="letter-spacing:-.3em;"/>

我尝试过的代码:-

driver.findElement(By.xpath(".//*[@data-reactid='.0.0.0.1:$=11:$1.1']")).click()‌​;

但我收到错误提示:-

找不到这样的xpath

【问题讨论】:

  • 我试过 driver.findElement(By.xpath(".//*[@data-reactid='.0.0.0.1:$=11:$1.1']")).click();但错误说它找不到这样的xpath
  • 元素是否在 iframe 中?如果是,则需要切换驱动程序以访问框架
  • 因为你的xpath没有问题,我也在网页中本地测试过它并且可以工作

标签: xpath css-selectors click webdriver dropdown


【解决方案1】:

可能有 iframe:-

driver.switchTo().frame("提供框架名称或位置");

请参阅下面有关打开框架的更多信息:-

http://toolsqa.com/selenium-webdriver/handling-iframes-using-selenium-webdriver/

您的 xpath 可能不正常或返回超过 1 个元素到 selenium。在这种情况下,硒会混淆硒应该点击哪个元素。所以再次检查你的xpath

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 2012-11-03
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多