【问题标题】:How to locate an element using an xpath that contains an apostrophe如何使用包含撇号的 xpath 定位元素
【发布时间】:2019-11-08 17:49:28
【问题描述】:

我正在尝试定位一个元素,它是一个包含提示文本的文本框:

<textarea placeholder="What's going on?"><textarea>

这是我尝试过的,但不起作用。

@FindBy(xpath="//textarea[@placeholder='What\'s going on?']")
public WebElement inputBox;

【问题讨论】:

标签: selenium xpath


【解决方案1】:

试试这个:

@FindBy(xpath="//textarea[@placeholder=\"What's going on?\"]")

它会转义周围的引号,以便正确处理引号。

【讨论】:

    【解决方案2】:

    请在xpath下面试试:

     //textarea[contains(@placeholder, "What's going on?")]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      相关资源
      最近更新 更多