WebdriverIO:无法单击下拉元素闪存列表按钮

WebdriverIO: Cannot click drop-down element flash list button

提问人:Daniel Yishai 提问时间:12/24/2019 最后编辑:iamdanchivDaniel Yishai 更新时间:1/4/2020 访问量:556

问:

我正在尝试使用 WebdriverIO 从下拉列表中单击“编辑”按钮:

enter image description here

检查下拉列表元素将生成以下 HTML 结构:

enter image description here

目前使用这种方法:

driver.findElement(By.xpath("//*[text()[contains(., '"+"Edit"+"')]]" )).click();

不幸的是,它并不担心。我应该如何继续让它工作?

selenium-webdriver xpath webdriver webdriver-io

评论

1赞 Sooraj 12/24/2019
建议添加 html 源代码而不是图像,并添加您在试用时遇到的异常/错误。
0赞 iamdanchiv 1/4/2020
丹尼尔,你正在为此使用 WebdriverIO 框架吗?如果是这样,下面的答案以及您的方法类似于 Java/C# 生态系统。如果这确实是WDIO问题,我会添加一个答案。

答:

0赞 Sooraj 12/24/2019 #1

尝试在 Xpath 中使用 normalize-space 函数:

//a[normalize-space(text())='Edit']

1赞 undetected Selenium 12/24/2019 #2

要单击该元素,您可以使用以下任一定位器策略

  • xpath1:

    driver.findElement(By.xpath("//a[@class='dropdown-item' and contains(., 'Edit')]" )).click();
    
  • xpath2:

    driver.findElement(By.xpath("//a[@class='dropdown-item' and normalize-space()='Edit']" )).click();