对于下面的DOM代码,我想获取日期字符串

时间:2019-07-09 09:34:46

标签: java selenium-webdriver automated-tests

address: {address1: this.myAddress1, address2: this.myAddress2, address3: this.myAddress3, address4: this.myAddress4} 

我已经尝试过定位器 <h5 class="val ng-binding"> Machine states <div class="dashboard-arrow fa fa-arrow-right"></div> July 9, 03:24 To July 9, 11:24 </h5> ,但我没有在h5标记中得到所有文本,我该如何得到它?我想念什么?

1 个答案:

答案 0 :(得分:0)

  1. 最好像这样使用contains() XPath Function

    //h5[contains(text(),'Machine states')]
    
  2. 如果要获取<h5> tag内的所有文本,请输入innerText property

    driver.findElementByXPath("//h5[contains(text(),'Machine states')]").getAttribute("innerText")
    

演示:

enter image description here