1
<tbody>
 <tr class="" style="height:65px;">
 <tr class="" style="height:65px;">
  <td class="dhx_matrix_scell" style="width:99px; height:64px;">Ashmita </td>
  <td>
   <div class="dhx_matrix_line" style="width:1181px; height:65px; position:relative;">
    <div class="dhx_marked_timespan dhx_matrix_now_time" style="height: 64px; left: 105px; width: 1px; top: 0px;"></div>
    <div class="dhx_marked_timespan gray_section" style="height: 64px; left: 588px; width: 591px; top: 0px;"></div>
    <div class="dhx_cal_event_line Booked" style="position:absolute; top:2px; height: 17px; left:99px; width:28px;" event_id="1374736442513">
    <table class="" cellspacing="0" cellpadding="0" style="width:1181px; height:65px;">
   </div>
  </td>
 </tr>
 <tr class="" style="height:65px;">
 <tr class="" style="height:65px;">
 <tr class="" style="height:65px;">
 <tr class="" style="height:65px;">
</tbody>

在上面的代码中,当我将鼠标悬停在元素上时 <div class="dhx_cal_event_line Booked" style="position:absolute; top:2px; height: 17px; left:99px; width:28px;" event_id="1374736442513">,我得到一个动态生成的工具提示提示;我无法使用火路捕捉它。我已经尝试过像这样的动作课

Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath(".//*[@id='scheduler']/div[3]/table/tbody/tr[2]/td[2]/div/div[4]"));
action.moveToElement(element).build().perform();
System.out.println("the tool tip text is"+element.getText());
action.moveToElement(element).release().build().perform();

但我得到 null 作为元素文本。

4

1 回答 1

2

当你这样做时:

Actions action = new Actions(driver);
    WebElement element = driver.findElement(By.xpath(".//*[@id='scheduler']/div[3]/table/tbody/tr[2]/td[2]/div/div[4]"));
    action.moveToElement(element).build().perform();

放一个String source = driver.getPageSource();然后将该源保存在某处(或将其打印到控制台)

查看页面源代码,看看哪个元素中有工具提示文本,然后您可以为它编写一个选择器。

于 2013-07-25T16:20:29.277 回答