【问题标题】:Want to Print the text on the XPath想要在 XPath 上打印文本
【发布时间】:2020-06-23 21:07:37
【问题描述】:
const myAdress = (`My Address = +${'//android.widget.TextView[@index="1"]'}`);
console.log(myAdress);

想要在这个特定的 XPath 上打印文本,但它按原样打印。

【问题讨论】:

    标签: javascript node.js appium webdriver-io appium-android


    【解决方案1】:
    const myAdress = (`My Address is ${$('//android.widget.TextView[@index="1"]').getText()}`);
    console.log(myAdress);
    

    括号有问题。

    这更清楚了:

    const element = $('//android.widget.TextView[@index="1"]') 
    const text = element.getText()
    console.log(`My address is ${text}`)
    

    【讨论】:

      【解决方案2】:

      可以在 xpath 中使用部分文本,而不是追加文本,例如

      String address = "//*[contains(@text,'replace your address')]"
      
      
      String printAddress= driver.findElementByXPath(address).getText();
      log.info(printAddress);
      

      【讨论】:

        猜你喜欢
        • 2023-01-01
        • 2022-07-26
        • 2017-12-09
        • 1970-01-01
        • 1970-01-01
        • 2013-10-06
        • 2020-10-12
        • 2021-10-09
        • 1970-01-01
        相关资源
        最近更新 更多