Selenium如何通过值(python)定位表中的单元格

时间:2015-10-14 06:51:32

标签: selenium

该表是动态生成的,单元格看起来像

<div class="tableRow">
  <input name="fileExt" type="hidden" value="complete">
  <div class="tableCell rbpCheckBox">
    <input data-index="0" name="SelectItem" type="checkbox" class="check" value="150909_ACTG_01_scyther_WD14R05C12.150910010134">
    <input name="SelectPFolderName" type="hidden" value="P_0_2015-09-10-010132_master_ac-analysis_v2.3.0">
  </div>
  <div class="tableCell accordion-toggle cursor-pointer" data-toggle="collapse" data-target="#collaspseDiv_150909_ACTG_01_scyther_WD14R05C12_150910010134">
    <p class="ellipsis rbpName" title="150909_ACTG_01_scyther_WD14R05C12">
      150909_ACTG_01_scyther_WD14R05C12
    </p>
    <input type="hidden" name="formatted_run_name" id="150909_ACTG_01_scyther_WD14R05C12.150910010134"
    value="150909_ACTG_01_scyther_WD14R05C12">
  </div>
  <div class="tableCell">
    <span class="rbpStatus rbpStatusPadding" title="multichunk analysis pending at master">
      <img src=" done.png " title="Done" class="runStatusImgTag">
    </span>
  </div>
  <div class="tableCell">
    <p class="rbpStatus">
      scyther
    </p>
  </div>
  <div class="tableCell">
    <p class="rbpStatus">
      2015-09-10 01:01:35
    </p>
  </div>
</div>

我必须按值找到单元格的原因是因为我想用它来确认页面上是否存在元素,并且我们已准备好在测试用例中进行下一步\动作,所以我必须等到页面上显示一些元素并决定等待这个单元格

<div class="tableCell">
  <p class="rbpStatus">
    scyther
  </p>
</div>

我正在尝试使用像

这样的东西
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "p.rbpStatus[contains('scyther')]")))

1 个答案:

答案 0 :(得分:0)

css选择器不支持contains功能。

等待 -

<div class="tableCell">
  <p class="rbpStatus">
    scyther
  </p>
</div>

试试这个:

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//p[contains(@class,'rbpStatus') and contains(text(),'scyther')]")))